odd cache behavior with memcached
code sample: http://dpaste.com/114571/ that code runs on every request to a certain page, which is being hit frequently. there are only 10 unique keys, and each of them gets requested several times within the 5-minute window of cache expiration. however, what seems to happen is that things are cached correctly for the first few minutes of restarting apache, but after that point, there are far more misses than there should be. there should be only 1 miss for each of the 10 keys in each 5-minute period, but instead it's 90% misses. apache, mod_python, memcached, ubuntu. i'm really puzzled as to what this could be. here's my memcached.conf for good measure. the only non-default is that i've increated the RAM to 128M. thanks in advance for any help you can offer! --lawrence # memcached default config file # 2003 - Jay Bonci# This configuration file is read by the start-memcached script provided as # part of the Debian GNU/Linux distribution. # Run memcached as a daemon. This command is implied, and is not needed for the # daemon to run. See the README.Debian that comes with this package for more # information. -d # Log memcached's output to /var/log/memcached logfile /var/log/memcached.log # Be verbose # -v # Be even more verbose (print client commands as well) # -vv # Start with a cap of 64 megs of memory. It's reasonable, and the daemon default # Note that the daemon will grow to this size, but does not start out holding this much # memory -m 128 # Default connection port is 11211 -p 11211 # Run the daemon as root. The start-memcached will default to running as root if no # -u command is present in this config file -u nobody # Specify which IP address to listen on. The default is to listen on all IP addresses # This parameter is one of the only security measures that memcached has, so make sure # it's listening on a firewalled interface. -l 127.0.0.1 # Limit the number of simultaneous incoming connections. The daemon default is 1024 # -c 1024 # Lock down all paged memory. Consult with the README and homepage before you do this # -k # Return error when memory is exhausted (rather than removing items) # -M # Maximize core file limit # -r --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Model for newbie
I'm guessing that you might have tried to do a ForeignKey(User) for the other_invited. If that is the case, then I think you need to add a related_name e.g. ForeignKey(User, related_name="group_invited_to"). You may have to do a related name for the creator as well. I hope that helps. On Jan 30, 8:16 pm, Kirillwrote: > Hello all! > > I have some logic problem I really don't understand how make model > for this task: > > I have registered users (i want to use User class). > Each registered user can create project (or group or blog) where he > can invite another users > So, how it's better to do model ? > > # > > from django.cotrib.auth.models import User > > class Project_or_Group_or_Blog(models.Model): > creator = models.ForeignKey(User) # many users for > one project. How it's will be written in table ? > other_invited = models. ? (User) # Here should be many > ids: first_id, second_id etc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Performance using session, passing data from one request to another, use js or not? Best practice?
Tim Daniel schrieb: > Thanks for the answer, I was already getting worried about my > 'session' way. No caching for know although it doesn't seem difficult > to implement. And yes the way you do it would have that advantage, but > mine has beautiful urls!! ^^ > thanks again, > > URLs are beautiful if they don't change (you can bookmark them) or send as them link. Sessions get deleted sooner or later. Thomas -- Thomas Guettler, http://www.thomas-guettler.de/ E-Mail: guettli (*) thomas-guettler + de --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Model for newbie
Hello all! I have some logic problem I really don't understand how make model for this task: I have registered users (i want to use User class). Each registered user can create project (or group or blog) where he can invite another users So, how it's better to do model ? # from django.cotrib.auth.models import User class Project_or_Group_or_Blog(models.Model): creator = models.ForeignKey(User) # many users for one project. How it's will be written in table ? other_invited = models. ? (User) # Here should be many ids: first_id, second_id etc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: charts in django
I've employed flot (http://code.google.com/p/flot/) with some success. It's pure javascript and requires jquery. On Thu, Jan 29, 2009 at 7:39 PM, Nick Lowrote: > > > I need to generate some line charts and bar graphs from django. I > > recall seeing a very promissing package a couple months ago and can't > > find it now. > > > > There's pychart, but it hasn't been maintained for a couple years and > > I question its staying power, and it just generates images. open- > > flash- > > chart has a python binding, but its documentation is very sketchy and > > I don't know how good its support is. visifire looks like it has a > > great future, but depends on silverlight which is not widely deployed > > yet. > > > > Any other ideas or comments on the above? > > I was using Open Flash Chart in a PHP project which is now a Python/ > Django one. This was before its more developed Python API, but it was > quite straightforward to use under both languages. Unfortunately it > lacked some of the charts we needed so we switched to XML/SWF charts > with minidom: > > http://code.google.com/p/open-flash-chart-python/ > http://www.maani.us/xml_charts/ > > Nick > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Snippets app ?
Hi djangonauts, For my site, I planned to include a snippets app and was thinking about cab [1] which powers djangosnippets or some other snippets app. For Cab, it looks it's not updated since April 2007 so I think it's not compatible with Django 1.0.x or do not take benefit from 1.0.x features and improvements. The code of snipt.net is no longer available on Google Code too. I found some pastebin app (like Spaste) but I wish more a snippets repository than a pastebin. Do someone know some snippets app available somewhere ? Regards, Nicolas [1] http://code.google.com/p/cab/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Validating and rendering dynamic form
I've created a dynamic form to allow users to upload images, and I'm trying to validate the form. - it displays fine, but when I validate and return a response, I get either a Key Error at the line (data = self.cleaned_data[dataName] ) in _clean_photo or I get a render error in my template at {{ image_form.as_table }} - I'm not too sure why sometimes I get either of the errors. In my view that gets posted to, i have: #images_submitted is a list of the names of the submitted image fields listingImages = make_image_form(images_submitted) image_form = listingImages(request.POST, request.FILES) The code calls into the make_image_form view to create the form: def _clean_photo(self, dataName): data = self.cleaned_data[dataName] if data != None: if data.size > max_photo_size: raise forms.ValidationError("The maximum image size allowed is 500KB") elif data.size == 0: raise forms.ValidationError("The image given is empty.") return data def make_image_form(image_fields): ''' Takes a list of image_fields to generate image fields ''' images = SortedDict() #a django sortedDict #create the ImageFields for the form for image_name in image_fields: images[image_name] = forms.ImageField(required=False) new_form = type('ListingImagesForm2', (forms.BaseForm,), {'base_fields' : images}) #now we add the validation methods to the class for image_name in image_fields: setattr(new_form, 'clean_' + image_name, lambda self: self._clean_photo(image_name)) #Add the _clean_photo method to the class setattr(new_form, '_clean_photo', _clean_photo) return new_form The _clean_photo method only gets called once - for the first photo. The ListingImagesForm2 class gets created fine, and the clean_photo_1, 2, 3 methods get created fine as well. I'm not too sure what's happening with the errors, but I think that it must have something to do with how I'm validating. When _clean_photo was called, self.cleaned_data had the image info for the first image only, when 2 or 3 images were posted. I hope I've provided enough information for help, any ideas as to what might be wrong will be highly appreciated :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: error when using delete generic views
On Thu, 2009-01-29 at 21:31 -0800, vierda wrote: > Dear all, > Thanks for your reply I have modified my code as per below : > > views.py : [...] > def delete (request): >user = request.user >if user.is_superuser: > if request.method == 'POST': > form = DeleteForm(request.POST) > if form.is_valid: > username = form.cleaned_data['username'] > user_delete = User.objects.get(username=username) > id_delete = user_delete.id > return delete_object(request,object_id = id_delete, > model=User, post_delete_redirect='/notify/success/', > template_name='delete.html',login_required=True) > else : > form = DeleteForm() > variables = RequestContext(request, {'form' : form}) > return render_to_response('delete.html',variables) [...] > the display_delete_profile run fine and exactly like I want, but > delete always raise error "The view > fintoo.apps.authorization.views.delete didn't return an HttpResponse > object." > I have google it and by example provided it relate to indentation > matters when put template renderer. but I think I don't have any > problem with that. please put some light and really appreciate for any > kind help. Thank you. It is kind of an indentation thing. Basically, every possible way of leaving the view function has to return an HttpResponse (which is what render_to_response() returns). Have a look at your view and notice what happens when user.is_superuser is False. The code falls off the bottom of the function, which implicitly returns None. You need to return something in that situation as well. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to pass the variable which is defined in the views.py to the jQuery function
On Thu, 2009-01-29 at 21:11 -0800, min wrote: > Hi. > > First, the code in the forms.py: > > class TestForm(forms.Form): > name = forms.CharField( max_length=30 ) > > Then, the variable is defined in the views.py: > > def Test_page(request): > form = TestForm() > show_results = False > variable = '' > if request.GET.has_key('name'): > show_results = True > query = request.GET['name'].strip() > variable = 'custom value' > variables = RequestContext(request, { > 'form': form, > 'show_results': show_results, > 'variable': variable > }) > return render_to_response('Test.html', variables) > > I know the value of variable can be accessed by using {{variable}} in > the Test.html. However, if I want use the jQuery in the Test.html and > pass the value of this variable to the jQuery function, how to do > that? > > I have tried: var x = $("variable").val(), and not succeed. The context dictionary you pass to render_to_response is used by render_to_response to produce a string. That string is what is sent back to the browsers. The variables (parameters, whatever we want to call them) are shoved into the template -- in a nice way; they're made very comfortable -- and become static data in the final result. That is, they are *not* variables from the browser's perspective. Template rendering happens fully on the server side. If you want to access this data via Javascript, you first have to make it available as a Javascript variable in the template. For example, you could write this in your template (inside a script block). var x = "{{ variable|escape_js }}"; The {{...}} bit is converted to a string by the (server-side) template rendering. Then "x" is available to the browser-side Javascript. Clear as mud? Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: error when using delete generic views
Dear all, Thanks for your reply I have modified my code as per below : views.py : def display_delete_profile(request): user = request.user if user.is_superuser: user_list = User.objects.all() return render_to_response ('delete.html', {'user_list':user_list}) def delete (request): user = request.user if user.is_superuser: if request.method == 'POST': form = DeleteForm(request.POST) if form.is_valid: username = form.cleaned_data['username'] user_delete = User.objects.get(username=username) id_delete = user_delete.id return delete_object(request,object_id = id_delete, model=User, post_delete_redirect='/notify/success/', template_name='delete.html',login_required=True) else : form = DeleteForm() variables = RequestContext(request, {'form' : form}) return render_to_response('delete.html',variables) forms.py: class DeleteForm(ModelForm): class Meta : model = User fields = ('username',) template: Delete User Please select username below for delete profile username : Please select as the default item in the list {% for user in user_list %} {{ user.username }} {% endfor %} the display_delete_profile run fine and exactly like I want, but delete always raise error "The view fintoo.apps.authorization.views.delete didn't return an HttpResponse object." I have google it and by example provided it relate to indentation matters when put template renderer. but I think I don't have any problem with that. please put some light and really appreciate for any kind help. Thank you. regards, -vierda- On Jan 29, 5:41 pm, Malcolm Tredinnickwrote: > On Wed, 2009-01-28 at 23:47 -0800, Daniel Roseman wrote: > > [...] > > > No, you have provided four keyword arguments. The signature for the > > delete_object function is as follows: > > def delete_object(request, model, post_delete_redirect, > > object_id=None, > > slug=None, slug_field='slug', template_name=None, > > template_loader=loader, extra_context=None, > > login_required=False, > > context_processors=None, template_object_name='object'): > > > So you need to pass request, model and post_delete_redirect *without* > > keywords, as simple positional arguments: > > return delete_object(request, User, '/notify/delete_done/', > > template_name='delete.html', login_required=True) > > Everything you've written is correct, except for this bit. You > emphasised the word "without" and that's not necessary. If a Python > function has this signature: > > def foo(a, b, c=None, d=6): > ... > > then you can quite happily use keyword arguments for the 'a' and 'b' > parameters. What is different about those parameters is that you *must* > supply them. They don't have default values. So foo(c=6, a=1, b='fred') > would be a valid way to call that function. > > The Python error message is slightly misleading here (and it is > generated by Python, not by Django). What they mean is that it takes two > required arguments. By definition (Python's syntax requires it), the > required arguments have to come before any default arguments, so they > can be passed in as positional arguments. But the keyword/non-keyword > argument distinction is actually a bit misleading in this case. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: building a blog site
Hi Muslu how can i can it yuor website to english. I dont uderstad that language. On Jan 19, 11:20 pm, "Muslu Yüksektepe"wrote: > i am preparing a blog site. > check outwww.yuksektepe.com > i will add how can make blog as soon as > thank you > from Turkiye > > 2009/1/19 joti chand > > > > > anyone knows is there any blog site development example in django --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to pass the variable which is defined in the views.py to the jQuery function
Hi. First, the code in the forms.py: class TestForm(forms.Form): name = forms.CharField( max_length=30 ) Then, the variable is defined in the views.py: def Test_page(request): form = TestForm() show_results = False variable = '' if request.GET.has_key('name'): show_results = True query = request.GET['name'].strip() variable = 'custom value' variables = RequestContext(request, { 'form': form, 'show_results': show_results, 'variable': variable }) return render_to_response('Test.html', variables) I know the value of variable can be accessed by using {{variable}} in the Test.html. However, if I want use the jQuery in the Test.html and pass the value of this variable to the jQuery function, how to do that? I have tried: var x = $("variable").val(), and not succeed. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Finding and Displaying the Object that a Comment is Created On
Thanks SO much. That did the trick. Dave On Jan 29, 1:28 pm, "alex.gay...@gmail.com"wrote: > On Jan 29, 3:48 pm, "dave.mer...@gmail.com" > wrote: > > > This si a somewhat nooby question. > > > I have a comment. I want to display the post title for the > > comment.object_id. > > > In the template I have been trying things like comment.post.title, but > > that is not working. > > > I think it is due to the fact that Comments use a generic foreign key. > > So... how do I do this? > > > Any references? > > > Lemme know. > > Dave > > comment.content_object.title > should get what you want --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Unique_together across classes
On Thu, 2009-01-29 at 19:54 -0800, CALdan wrote: > hi! > > I'm putting together a simple model in Django as an example for a > large project. I'm attempting to set up the models in an efficient > manner with as little redundancy as possible (none). > > What I'm attempting to do is use unique_together across 2 classes > which are linked through their primary key fields, with the > unique_together referencing a field from each table which are not the > primary keys. > > Is it possible to use unique_together across classes like this? If > not, what alternative could I use that's clean and efficient? You can't add the lines -> survey unique constraint through Django's ORM. The Meta.unique_together attribute is only for adding a constraint to fields on the table for that model. You're needing a more complex check constraint at the database level and this isn't supported. You could add it as a table modification using raw SQL (via, say, the post-syncdb hook, or just manually), but it won't be handled by things like form validation, so will be a little tricky to work with. One workaround is to wait a little bit until model-aware validation lands and add model-level validation as well, to the Lines model, to do this checking. That wouldn't completely remove the possibility of an IntegrityError when you save to the databse, but no uniqueness checks at the Python level can do that (it can be unique when we validate and something else can have written to the database before we save), but it's a way of making it work more smoothly. By "smoothly" here, I'm meaning having some way of detecting a potential clash before calling save() and seeing an IntegrityError returned from the database. > The rules that need to be adherred to within the model are as follows: > > 1.Survey's have many Lots. > > 2.Within a Survey, Lot numbers must be unique. > > 3.Lot's have many Lines. > > 4.Within a Survey, Line numbers must be unique. > > The models are posted below with the fields in question in bold. > > class Survey(models.Model): > survey = models.IntegerField(primary_key=True, unique = True) > > class Meta: > ordering = ["survey"] > db_table='survey' > > class Lot(models.Model): > lot_id = models.AutoField(primary_key=True, unique = True) > lot_number = models.IntegerField() > survey = models.ForeignKey(Survey, db_column ='survey') > > class Meta: > ordering = ["lot_number"] > db_table='lot' > unique_together = ("lot_number", "survey") > > class Line(models.Model): > line_id = models.AutoField(primary_key=True, unique = True) > lot_id = models.ForeignKey(Lot, db_column='lot_id') You should consider renaming the attribute here to just "lot" (or something similarly descriptive; "lot" would require you to add a related_name attribute). The thing is, from a Python perspective, that attribute does *not* hold the lot_id. It actually contains a Lot instance whenever you're using. It's a Lot, not an id. There will be a "hidden" attribute generated on the model called (in your case) lot_id_id, which will be the actual lot_id, but you never interact with that. Code that uses "lot_id", when it really means "lot instance" tends to be confusing to read in six months time (it's a common first stab at naming and I've seen it enough in client code to want to warn people away from it). Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: reason for missing readline() in uploaded files?
On Thu, Jan 29, 2009 at 9:28 PM, Malcolm Tredinnickwrote: > > On Thu, 2009-01-29 at 15:40 -0500, Todd O'Bryan wrote: >> I'm trying to validate an uploaded csv file, so I want to read the >> first line of text and if it's not the right format, send an error >> message. Unfortunately, neither InMemoryUploadedFile nor >> TemporaryUploadedFile have the readline() method. >> >> Was that an oversight (in which case I'll create a two-line patch and >> submit it--both StringIO and temp files support the method) or a >> design decision with a good reason? > > It's a flaw in Python: what an object needs to be "file-like" is not > well defined. Different users require different things. A file doesn't > really need a readlines() method, except when it does, etc. > > There's about half a dozen tickets open for "add X, Y or Z" to the file > stuff, so look through those first. > > Regards, > Malcolm > OK. I proxied every file-like object method or attribute listed in the Python docs. If something doesn't work now it's because the object that backs the UploadedFile doesn't support it, not because we forgot to provide a proxy to it. http://code.djangoproject.com/ticket/9404 Todd --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Unique_together across classes
hi! I'm putting together a simple model in Django as an example for a large project. I'm attempting to set up the models in an efficient manner with as little redundancy as possible (none). What I'm attempting to do is use unique_together across 2 classes which are linked through their primary key fields, with the unique_together referencing a field from each table which are not the primary keys. Is it possible to use unique_together across classes like this? If not, what alternative could I use that's clean and efficient? The rules that need to be adherred to within the model are as follows: 1.Survey's have many Lots. 2.Within a Survey, Lot numbers must be unique. 3.Lot's have many Lines. 4.Within a Survey, Line numbers must be unique. The models are posted below with the fields in question in bold. class Survey(models.Model): survey = models.IntegerField(primary_key=True, unique = True) class Meta: ordering = ["survey"] db_table='survey' class Lot(models.Model): lot_id = models.AutoField(primary_key=True, unique = True) lot_number = models.IntegerField() survey = models.ForeignKey(Survey, db_column ='survey') class Meta: ordering = ["lot_number"] db_table='lot' unique_together = ("lot_number", "survey") class Line(models.Model): line_id = models.AutoField(primary_key=True, unique = True) lot_id = models.ForeignKey(Lot, db_column='lot_id') line_number = models.IntegerField() class Meta: ordering = ["line_number"] db_table='line' unique_together =[("Lot.survey"), ("line_number")] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: charts in django
> I need to generate some line charts and bar graphs from django. I > recall seeing a very promissing package a couple months ago and can't > find it now. > > There's pychart, but it hasn't been maintained for a couple years and > I question its staying power, and it just generates images. open- > flash- > chart has a python binding, but its documentation is very sketchy and > I don't know how good its support is. visifire looks like it has a > great future, but depends on silverlight which is not widely deployed > yet. > > Any other ideas or comments on the above? I was using Open Flash Chart in a PHP project which is now a Python/ Django one. This was before its more developed Python API, but it was quite straightforward to use under both languages. Unfortunately it lacked some of the charts we needed so we switched to XML/SWF charts with minidom: http://code.google.com/p/open-flash-chart-python/ http://www.maani.us/xml_charts/ Nick --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django Forms in HTML 4.01 Strict
On Thu, 2009-01-29 at 15:18 +0100, Gertjan Klein wrote: > Malcolm Tredinnick wrote: > > >On Wed, 2009-01-28 at 14:33 +0100, Gertjan Klein wrote: > >> Malcolm Tredinnick wrote: > >> > >> I disagree. When I develop web pages (using Django or otherwise) I use > >> the Firefox HTML validator extension. This helps me write > >> standards-compliant HTML -- a big red cross indicates a problem in my > >> page. It is annoying if that big red cross no longer indicates anything > >> (there might be problems *I* caused, or it might just be Django stuff). > > > >You realise that you're effectively confirming what I said, right?. The > >big red cross is a cosmetic issue. The fact that it makes precisely zero > >difference to the practical matter of how a real-world web browser > >processes the page means it's not fatal/tragic. > > No, I think you may have misunderstood me. The XHTML slash is cosmetic; > to my knowledge, all current browsers are capable of dealing with that > (thus deviating from what the standard dictates them to do, but > practicality beats purity, I guess ;)). XHTML, being XML, is consumed by much more than just web browsers and should be targeted at being correctly parsed and rejected by any conforming XML library (feed readers being one example). Conformance to the XML requirement that errors are fatal is therefore important. HTML is sufficiently screwed up that it's not really possible to level that requirement against it. > However, *my* HTML (as opposed to Django's generated HTML) may contain > errors as well, and regularly does. The big red cross in an invaluable > indicator that I messed something up, and losing that functionality is > annoying. In other words, there is a slight, but annoying, problem with such tools, in that they don't differentiate between errors that are going to cause real problems and those which aren't. That happens to interact with a slight, but annoying, problem in Django. No harm, no foul. Things could be better on both sides and one day people might change them. I'm completely in favour of 100% valid HTML code wherever possible. But I'm more in favour of knowing why that isn't compulsory and not always possible, and why there does need to be some differentiation. > Now, when using HTML as opposed to XHTML, I can no longer see > if I did something wrong, as the page is *always* in error (from a > standards compliance POV). > > >Then you'll have no trouble creating a parallel set of form widgets or a > >form framework that can handle this and everybody will be happy. :-) > > No, I have no desire to do such a thing. As I stated before, the > practical solution for me was to switch to XHTML. > > >Or look at the django-html project on Google Code, where various ideas > >are being tried out. > > I did, briefly, and didn't like what I saw. They overcomplicate things, > IMHO. I don't want DOCTYPE management, for example. Which shows why it's a harder problem than it looks on the surface, once you start looking at the details. Explains why it isn't in Django yet. > >(you're certainly paid just as much to work on Django as me, for > >example). > > This payment thing comes up regularly here, and pollutes the discussion. > I have been using Django for a while, and found it to have good things > and downsides (both IMHO). I have not even critisized Django here (yet > ;)), just expressed mild curiousity. I don't think I've given you reason > to bring up that you're not payed for your work on Django. Take it in the spirit it was offered, dude. Exactly the same tone as you used. It was part of a broader explanation about why this feature/enhancement isn't in Django and was only mentioned as part of a sentence in the second or third response because you kept going on about how the cosmetic thing was much more important to you. Let's keep some perspective, please. I wasn't intending to cause offence. If you're going to go on about something, I'm going to give you the full list of reasons why the state of play is as it is and how it can be made better. If you don't want the answer, don't ask the question. > >Maintaining two copies of everything certainly adds to the workload. > > I have not suggested such thing though. From a brief look at the source > code, it appeared to me that it would be easy to create a setting that > specifies whether to include the slash or not, and based on that setting > write either " />" or ">" at the end of input tags (and ). It's a question of which compromises should be made and where. You've indicated you'd be happy without that, for others, it would still be a hack if they don't have the DOCTYPE control (for the record, I have precisely no opinion on that yet). That's the fun of working with this stuff: never able to please everybody immediately. I think we should probably move on now. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google
Re: passing self?
Hope out loud is really all i was trying to do also - I'm not demanding a solution of you. And please believe me when i say i am very appreciative of your work on django personally. I actually love the framework and have been able to, rather quickly, throw together vast portions of my envisioned project with little to no trouble. However, as someone who has been developing for several years, i have become accustomed to building interfaces that operate in a certain way. I really like using tree structures and for this project it is very important to do so. With each new framework I've learned, even in PHP which I've been using for years - such as CakePHP or Zend with Doctrine - one of my first "battles" with the framework how to generate tree menus and inputs, whether it be something simple like an indented select list (that's what I was trying to do in the discussions above - my first question was more direct but no one responded) -- or something like an expandable, animated tree which interacts with javascript. For me when I reach a point where I need that, I can't move forward until I've figured out how to do it. So I wasn't really trying to modify how Django works at all - I was just trying to accomplish one of a handful of specific functionalities I would need for my projects. While it may be simple to others, I am nonetheless proud of what I came up with. It felt really good to get it working, and understand why it works: http://pastebin.com/f50991c2c It relies upon django-mptt to work, which operates similarly to other tree behavior packages I've used in the past. I know everyone here is a volunteer. I myself am not doing this project for pay, but to benefit a larger community I am a part of. I don't ask anything of anyone that they do not have the time or energy to give. And if anything I've said has seem directed at you, I certainly do not mean it. As I said you have been very fair with me. I think I am just needing to vent now that I have finally accomplished this one simple task but had a few interactions that definitely made it harder. As for your suggestion to start a beginners django group - it is not that I am opposed to that, but as I am only a beginner myself I am not sure it would be very appropriate or effective. As I myself could not volunteer on that project in terms of answering beginner's questions, it would seem a little presumptuous. However, creating some sort of forum geared towards beginners for a variety of languages/platforms - now that might be something worth taking on at some point. On Jan 29, 9:46 pm, Malcolm Tredinnickwrote: > On Thu, 2009-01-29 at 15:47 -0800, ajlozier wrote: > > Hi Malcolm, > > > I figured it out. This article is what pointed me in the right > > direction: > > >http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/ > > > While you are right that there are a lot of examples in the code of > > something similar, and that, in theory, I should be able to find the > > answer to any question by perusing the source code, it doesn't > > necessarily work for beginners - especially beginners who don't have a > > strong python background. I am guessing django wants to attract all > > kinds of developers, even those who are just starting to learn python, > > am I right? Or maybe not. > > We aim to support and welcome all people, but beginners aren't the > primary audience. Partly because you're only a beginner at the start. > Django's primary audience is something like people or teams who are > comfortable with Python, web tech (HTML, javascript, CSS, etc) up to the > level they wish to employ it, and databases (this is where we are > probably have the most shielding over ugly reality) and want something > to make the routine stuff faster (that's a very rough précis). It's not > too difficult to bootstrap from zero up to that level, but it's not > something that happens overnight. > > Regarding Python, particularly, Django is designed to provide a Python > interaction or Python-like interface to a bunch of stuff. So, yes, it > absolutely requires familiarity with Python. Before embarking on using > Django, preferably. > > As I've suggested a couple of times in this thread, whilst at the > beginner level, you have to set goals that correspond: work with the fat > part of the feature list, the 90% that are documented with English > descriptions and example code. Wandering off into the other 10% from day > one is possibly interesting and exciting, but not the route to rapid > enlightenment -- and if you're willing to take the time, that's fine. > Time/experience/goals form a trade-off triangle here. > > I certainly take the position that if somebody isn't comfortable with > Python, then diving around customising Django is not the right place to > be working. It takes a couple of days to a couple of weeks to get really > comfortable with Python. Working through "Dive into Python" and the > python tutorial and/or one
Re: Any way to NOT escape a percent sign using 'contains'?
On Thu, 2009-01-29 at 18:47 +, Adam Stein wrote: > According to the docs, when using 'contains' in filter() a percent sign > or underscore is automatically escaped. However, in my case I want the > resulting SQL to use the percent sign. > > I know 'contains' will fill in the outside percent signs, but it escapes > the percent sign in my string. So that calling: > > Entry.objects.filter(headline__contains='a%b') > > will result in: > > SELECT ... WHERE headline LIKE '%a\%b%'; Because the "contains" lookup type is used to look for string containment, not as a proxy for SQL. We deliberately try to not leak the underlying SQL abstraction (the storage backend may not even be SQL, after all). > > but I want it to be this instead: > > SELECT ... WHERE headline LIKE '%a%b%'; > > This there an easy way to do this? > > I could use regexp, but I didn't want people to know that they would > have to use "a.*b" instead of "a*b", just trying to make it simplier for > myself and the people using the system. Well, the regexp lookup type is for this purpose, so it's the right tool to use at the code level. The point about the user-interface is well taken, but it doesn't have to be a transparent pass-through. What I would suggest is converting your value by doing using value = value.replace('%', '.*') at some point. If these values are coming in through a form field, a custom cleaning method for the form field would be a nice level to this at, for example. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: TINYMCE causing form error "This field is required."
Thanks for your help Daniel, That was exactly my problem. I changed the ModelForm in admin.py to this and it resolved the issue. class EntryAdminForm(forms.ModelForm): body_html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30})) excerpt_html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}), required=False) On Jan 26, 3:55 am, Daniel Rosemanwrote: > On Jan 26, 5:22 am, "Eric I.E." wrote: > > > > > When I addTinyMCEto my form fields it turns them from optional > > (blank=True, null=True) into required fields. > > I am using django-tinymcein conjunction with django-filebrowser. > > > My field is defined in models.py like this: > > column1 = models.TextField(help_text="Extended Info", blank=True, > > null=True) > > > and theTinyMCEeditor is applied in the admin.py > > class NewsItemAdminForm(forms.ModelForm): > > column1 = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': > > 25})) > > > Everthing performs as expected until saving when I receive an error > > reading "This field is required." > > RemovingTinyMCEremoves the error. Any ideas where to start with that > > one? > > This is standard behaviour, not connected toTinyMCE. If you override > any field in a modelform, you need to specify all the options - > including whether it's a required field or not. > -- > DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: charts in django
Chris Haynes wrote: > I need to generate some line charts and bar graphs from django. I > recall seeing a very promissing package a couple months ago and can't > find it now. [snip] > Any other ideas or comments on the above? Linux Journal's most recent print-edition had a good article introducing the Dojo toolkit, including for graphing. I have a junior developer investigating this toolkit for some of our own in-house charting/graphing needs. -tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: passing self?
On Thu, 2009-01-29 at 15:47 -0800, ajlozier wrote: > Hi Malcolm, > > I figured it out. This article is what pointed me in the right > direction: > > http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/ > > While you are right that there are a lot of examples in the code of > something similar, and that, in theory, I should be able to find the > answer to any question by perusing the source code, it doesn't > necessarily work for beginners - especially beginners who don't have a > strong python background. I am guessing django wants to attract all > kinds of developers, even those who are just starting to learn python, > am I right? Or maybe not. We aim to support and welcome all people, but beginners aren't the primary audience. Partly because you're only a beginner at the start. Django's primary audience is something like people or teams who are comfortable with Python, web tech (HTML, javascript, CSS, etc) up to the level they wish to employ it, and databases (this is where we are probably have the most shielding over ugly reality) and want something to make the routine stuff faster (that's a very rough précis). It's not too difficult to bootstrap from zero up to that level, but it's not something that happens overnight. Regarding Python, particularly, Django is designed to provide a Python interaction or Python-like interface to a bunch of stuff. So, yes, it absolutely requires familiarity with Python. Before embarking on using Django, preferably. As I've suggested a couple of times in this thread, whilst at the beginner level, you have to set goals that correspond: work with the fat part of the feature list, the 90% that are documented with English descriptions and example code. Wandering off into the other 10% from day one is possibly interesting and exciting, but not the route to rapid enlightenment -- and if you're willing to take the time, that's fine. Time/experience/goals form a trade-off triangle here. I certainly take the position that if somebody isn't comfortable with Python, then diving around customising Django is not the right place to be working. It takes a couple of days to a couple of weeks to get really comfortable with Python. Working through "Dive into Python" and the python tutorial and/or one of any number of other online and paper-based resources. Taking that time to save effort and stress later on is surely worth it. > > I'd just like to make one observation. On every page of the django > introductory tutorial there is the following at the bottom: > > Questions/Feedback > > Having trouble? We'd like to help! > > * Try the FAQ — it's got answers to many common questions. > * Search for information in the archives of the django-users > mailing list, or post a question. > * Ask a question in the #django IRC channel, or search the IRC > logs to see if its been asked before. > > It sounds so welcoming, but the reality for us beginners is not so > rosy. I went in this exact order. Searched the documentation. > Couldn't figure it out. Posted a question in the user group - first > one wasn't answered. Then tried the IRC chatroom - boy that was a > mistake! The general reception I have received is that if you don't > know how to do this you have no business being here. RTFM. Now, I'm > not talking about you personally because you have been very civil to > me and I appreciate that. Bearing in mind that what you're trying to do (and having read the earlier thread and obviously paid attention here, I still don't really know what you're trying to do beyond customise ModelForm in some deep fashion) *is* in the 10% I spoke about above, you are going to have to look a bit harder. I'm sorry you had the experiences you had in IRC. IRC isn't for everybody and I don't wish to speak ill of others' efforts, so I won't comment further. > > But I do think this is a general problem in the developer community. > I'm a beginner to django/python, but not a beginner to programming, > even object-oriented programming. I've learned a few languages and > frameworks over the years and my experience has been similar with all > of them. I hit some rather, in retrospect, trivial roadblocks in the > beginning but once I get over a few humps my understanding accelerates > exponentially. But user groups and chat rooms have been, overall, the > least helpful - or even demoralizing - tools for me. I really don't > think I'm alone, either. Well, I hate to put it like this, since some people get upset at having it pointed out that this is Open Source and we are all volunteers, but things like IRC chat rooms are run by volunteers who have time. So if you think a beginner's room is what's required, organise yourself and a few people to set one up. You can get publicity for it pretty easily (post here, send a note to "this week in Django", etc) and see what happens. Right now, all the people helping out are doing so (hopefully) to the best of their ability and available
Re: charts in django
Pygooglechart is a good interface to the Google charting API: http://pygooglechart.slowchop.com/ --Ned. http://nedbatchelder.com Chris Haynes wrote: > I need to generate some line charts and bar graphs from django. I > recall seeing a very promissing package a couple months ago and can't > find it now. > > There's pychart, but it hasn't been maintained for a couple years and > I question its staying power, and it just generates images. open-flash- > chart has a python binding, but its documentation is very sketchy and > I don't know how good its support is. visifire looks like it has a > great future, but depends on silverlight which is not widely deployed > yet. > > Any other ideas or comments on the above? > > Thanks, > Chris Haynes > > > > > > > -- Ned Batchelder, http://nedbatchelder.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Apps and static/media files
On Fri, 2009-01-30 at 00:57 +0200, Erik Allik wrote: > I'm having a situation in which two of my reusable apps both use > FCKeditor in their admin interface. Since both of them require > FCKeditor library files, I'm confused which one should provide them? > Both? How? What is the idiomatic/standard way of doing this? Should I > instead have them both just assume "{{ MEDIA_URL }}lib/fckeditor/ > fckeditor.js" exists and document this requirement/assumption in the > docs of both apps? > > (This is a general media/static files question, I'm just bringing > FCKeditor as an example.) I'd do the latter. Whether you use MEDIA_URL or some other URL for static, unchanging media is up to you. MEDIA_URL is the brother of MEDIA_ROOT and is required for file upload support, but it isn't necessarily going to be the only place you use to serve static files. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: reason for missing readline() in uploaded files?
On Thu, 2009-01-29 at 15:40 -0500, Todd O'Bryan wrote: > I'm trying to validate an uploaded csv file, so I want to read the > first line of text and if it's not the right format, send an error > message. Unfortunately, neither InMemoryUploadedFile nor > TemporaryUploadedFile have the readline() method. > > Was that an oversight (in which case I'll create a two-line patch and > submit it--both StringIO and temp files support the method) or a > design decision with a good reason? It's a flaw in Python: what an object needs to be "file-like" is not well defined. Different users require different things. A file doesn't really need a readlines() method, except when it does, etc. There's about half a dozen tickets open for "add X, Y or Z" to the file stuff, so look through those first. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Cron Job Question
On Thu, 2009-01-29 at 11:34 -0800, Chris wrote: > I have a python / django script that I have written which will be > used as a cron. Basically this script goes out to my database and gets > rows from a given table and performs a specific task then deletes the > row once finished. What I would like to do is have multiple instances > of this script running to check for new additions to this table every > 15 minutes or so. I am not sure how I can divide up the work to be > processed among all running scripts with out having issues. > > Currently the script does an .objects.all() call and runs through the > entire list but as mentioned would like to find a way to divide this > up and with out another instance trying to process a row that is being > processed by another instance. > > The main question would be how I can tell the script to not process a > given row b/c another instance of the script is currently processing > the row or is in its queue to be processed. > > It would also be nice to be to have the ability to add or remove > instances of the script in times when the table is more or less full > with rows to process. In other words, you need a persistent queue. Put things into the queue, pop the leading element for next processing. There are a lot of options around. Here's a reasonable place to start: http://code.google.com/p/queues/ Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can I control contents of SELECT in queryset?
On Thu, 2009-01-29 at 06:44 -0800, phoebebright wrote: > I want a distinct list of all the 'cat__names' that exist in > Subcategory and have at least one entry in Business (Business is a > subclass of model Directory which might be the problem) > > dir_query = Business.objects.all().select_related().distinct() > ... > subcats = dir_query.values('cat__name','cat').select_related().distinct > () > > But the SQL this generates has an additional field in the SELECT > statement which means the DISTINCT does not have the effect I want and > selects all entries. > > SELECT DISTINCT `town_subcategory`.`name`, `town_business`.`cat_id`, > `town_directory`.`name` > FROM `town_business` > INNER JOIN `town_subcategory` ON (`town_business`.`cat_id` = > `town_subcategory`.`id`) > INNER JOIN `town_directory` ON (`town_business`.`directory_ptr_id` = > `town_directory`.`id`) > ORDER BY `town_directory`.`name` ASC > > > Is there some way of forcing the fields in the select statement > without having to write the whole SQL in raw format? Or another way > of writing the query? Even if you could do what you wanted here, it wouldn't solve your problem. You're implicitly using the select fields and the inner join to enforce the "a name exists" constraint. Django won't just add an arbitrary table in via an extra inner join if it's not required. There's a better solution to your problem, though. It's a little hard to tell what the exact queryset will look like, since I don't understand your models entirely, but this should be close. Firstly, you want subcategory names, so that's the model to filter on. the constraint "must have at least one business" is a filter on the business related attribute being not-None: SubCategory.objects.values('name').exclude(business=None) Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
charts in django
I need to generate some line charts and bar graphs from django. I recall seeing a very promissing package a couple months ago and can't find it now. There's pychart, but it hasn't been maintained for a couple years and I question its staying power, and it just generates images. open-flash- chart has a python binding, but its documentation is very sketchy and I don't know how good its support is. visifire looks like it has a great future, but depends on silverlight which is not widely deployed yet. Any other ideas or comments on the above? Thanks, Chris Haynes --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django Forms in HTML 4.01 Strict
On Thu, 2009-01-29 at 06:36 -0800, Andrew Ingram wrote: > On Jan 29, 2:18 pm, Gertjan Kleinwrote: > > This payment thing comes up regularly here, and pollutes the discussion. > > I have been using Django for a while, and found it to have good things > > and downsides (both IMHO). I have not even critisized Django here (yet > > ;)), just expressed mild curiousity. I don't think I've given you reason > > to bring up that you're not payed for your work on Django. > > Off-topic: > > For what it's worth I agree with you. I've lost track of the number of > times i've found bugs in open source software and been not-so-subtly > told to contribute the fix myself. Or asked about something that I > think should be included and been told to write it myself. > > As a consumer of software libraries it is not my job to fix them, It's rarely anybody's job to fix them, in the greater scheme of things. That's the whole point and why I think Gertjan's comment above is an over-reaction. We are *all* on a level playing field here. If somebody says something like "I wondered why it isn't in; it doesn't seem like a lot of work" in a light-hearted manner, they will often get a reply in the same tone, pointing out one of the many reasons why it isn't in there is that the person in question hasn't contributed a patch to add it. Itches get scratched by the people who have them, particularly enhancement requests. Sure, sometimes you can't fix the things, but then that's life. You made that risk evaluation going in. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: form for two models - reuse fields generated by modelform
On Thu, 2009-01-29 at 03:56 -0800, Markus Bertheau wrote: > Hi, > > I need a registration form that allows the user to input several > models. Now just creating two ModelForms and letting a third class > inherit from them doesn't work, the fields of one model don't show. Is > there another way to reuse the part of ModelForms that create > FormFields from ModelFields? I'd avoid trying to make them into a single form class. A Form subclass in Django (which includes ModelForms) is only a part of the HTML-side form. So you can use multiple Form subclasses to generate a single HTML form. Furthermore, when you pass data to a form for validation, it ignores any input that isn't part of the form, so you can pass request.POST to both forms without having to work out which fields belong to which form. You might well want to investigate the "prefix" option ([1]) if there's a chance of field name collision. By way of example (completely untested, but likely to be close): def my_view(request): if request.method == "POST": form_a = ModelAForm(request.POST, prefix="a") form_b = ModelBForm(request.POST, prefix="b") if form_a.is_valid() and form_b.is_valid(): # return http.HttpResponseRedirect(...) else: form_a = ModelAForm(prefix="a") form_b = ModelBForm(prefix="b") data = { "form_a": form_a, "form_b": form_b, } return render_to_response('form.html', data) If you're doing this with N models (for some large-ish value of N), it's easy enough to make a loop to create the forms and check validity, etc. For a different example, see [2]. [1] http://docs.djangoproject.com/en/dev/ref/forms/api/#prefixes-for-forms [2] http://www.pointy-stick.com/blog/2008/01/06/django-tip-complex-forms/ Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Complex queries with datetime field
On Thu, 2009-01-29 at 09:48 +0100, Stefan Tunsch wrote: > Well, first of all I can't believe I've overlooked the __in field > lookup... I wasn't aware of it's existance. Sorry. > > Regarding the __year, __month and __day lookups I'm using in my code: > I do it because I want to filter all datetime objects of a specific > day. I want to filter all datetime objects like > datetime.datetime(2009, 1, 29, 12, 33, 41, 234000) that are in a day > like datetime.date(2009, 1, 29). > > I would want to do something like > mydatetimefield__date=datetime.date(2009, 1, 29) but since that option > does not exist, I am doing this strange thing with year, month and > day. Since you've just discovered one new lookup type, it's not going to shock you that there are other good ones out there, too. Today would be a good day to learn about "__range":" pass in the midnight and 23:59:59 on the day in question and you're down to two lookups. Or use __gte midnight and __lt midnight on the following day. In fact, most databases will treat a date range as being between the two midnights for datetime columns (SQLite is a little fussy there, but MySQL and PostgreSQL behave nicely). So, Q(foo__range=(, )) will likely do what you want. The only reason I'm emphasising these alternatives is that, if you're doing those queries a lot and need to index those columns for speed, setting up an index to allow efficient date range comparisons is easier than creating a functional index for each of the year, month and date lookups (and, if you're using MySQL, say, you can't even do functional indexes). Plus, it's a heck of a lot easier to debug at the Python level with a single datetime object that three variables that have to be train-wrecked together to work out the date each time. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: error when using delete generic views
On Wed, 2009-01-28 at 23:47 -0800, Daniel Roseman wrote: [...] > No, you have provided four keyword arguments. The signature for the > delete_object function is as follows: > def delete_object(request, model, post_delete_redirect, > object_id=None, > slug=None, slug_field='slug', template_name=None, > template_loader=loader, extra_context=None, > login_required=False, > context_processors=None, template_object_name='object'): > > So you need to pass request, model and post_delete_redirect *without* > keywords, as simple positional arguments: > return delete_object(request, User, '/notify/delete_done/', > template_name='delete.html', login_required=True) Everything you've written is correct, except for this bit. You emphasised the word "without" and that's not necessary. If a Python function has this signature: def foo(a, b, c=None, d=6): ... then you can quite happily use keyword arguments for the 'a' and 'b' parameters. What is different about those parameters is that you *must* supply them. They don't have default values. So foo(c=6, a=1, b='fred') would be a valid way to call that function. The Python error message is slightly misleading here (and it is generated by Python, not by Django). What they mean is that it takes two required arguments. By definition (Python's syntax requires it), the required arguments have to come before any default arguments, so they can be passed in as positional arguments. But the keyword/non-keyword argument distinction is actually a bit misleading in this case. Regards, Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Meta-information for model and form fields
On Wed, 2009-01-28 at 23:21 -0800, Vinay Sajip wrote: [...] > I was hoping there was another way. Of course subclassing's not hard > to do, but it means doing it for every field class. I was looking at > moving an application over from SQLAlchemy, which offers this feature > both for models and fields. That's not very natural Python behaviour, though. You can't expect to pass in extra arbitrary arguments to class constructors for normal Python classes and have them hold onto it for later collection. Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Three table Lookup Question
Yes, almost. It got me to understand the correct syntax. I noticed that my results were coming according to Industry's primary key, rather than the Industry integer field, so I appended another __industry Here is the solution: Project.objects.filter(campaign__industry__industry=x) Thank you for your guidance, Todd. On Thu, Jan 29, 2009 at 12:33 PM, Todd O'Bryanwrote: > > I'm not sure I understand what you're asking, but > > projs = Project.objects.filter(campaign__industry=x) > > where x is one of 1-6 should do what you want, I think. > > Is that what you were asking? > > On Thu, Jan 29, 2009 at 9:54 AM, Kyle wrote: > > > > Hello! > > > > I am trying to get a list of "Projects" based on certain "Industry". > > (My naming convention, not django's) > > > > My models look like this: > > http://dpaste.com/114308/ > > > > "Project" has a foreign key to "Campaign". > > > > "Industry" also has a foreign key to "Campaign". > > > > Does it matter if both relationships are pointing to the center model > > in the data route I am trying to setup? Like this: > > > > Project -> Campaign <- Industry > > > > If Industry = 3, and a handful of Campaigns are returned, I would like > > a list of all the Projects contained in each of the Campaigns > > returned. > > > > How do I do this with django models? > > > > > > > > > > > -- Light Emitter Think in 3D Studios www.thinkin3d.net --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: passing self?
Hi Malcolm, I figured it out. This article is what pointed me in the right direction: http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/ While you are right that there are a lot of examples in the code of something similar, and that, in theory, I should be able to find the answer to any question by perusing the source code, it doesn't necessarily work for beginners - especially beginners who don't have a strong python background. I am guessing django wants to attract all kinds of developers, even those who are just starting to learn python, am I right? Or maybe not. I'd just like to make one observation. On every page of the django introductory tutorial there is the following at the bottom: Questions/Feedback Having trouble? We'd like to help! * Try the FAQ — it's got answers to many common questions. * Search for information in the archives of the django-users mailing list, or post a question. * Ask a question in the #django IRC channel, or search the IRC logs to see if its been asked before. It sounds so welcoming, but the reality for us beginners is not so rosy. I went in this exact order. Searched the documentation. Couldn't figure it out. Posted a question in the user group - first one wasn't answered. Then tried the IRC chatroom - boy that was a mistake! The general reception I have received is that if you don't know how to do this you have no business being here. RTFM. Now, I'm not talking about you personally because you have been very civil to me and I appreciate that. But I do think this is a general problem in the developer community. I'm a beginner to django/python, but not a beginner to programming, even object-oriented programming. I've learned a few languages and frameworks over the years and my experience has been similar with all of them. I hit some rather, in retrospect, trivial roadblocks in the beginning but once I get over a few humps my understanding accelerates exponentially. But user groups and chat rooms have been, overall, the least helpful - or even demoralizing - tools for me. I really don't think I'm alone, either. Let me just say that I don't jump to these types of resources quickly by any means - its always a last resort. And each time I am hoping there is someone out there who is kind enough to show me a little guidance. But it seems like there is a pretty high threshold for being welcomed into these communities which is certainly not indicated in the very welcoming statement: "Having trouble? We'd like to help." In fact I would say the reception for most beginners is pure hostility. What usually happens for me is by the time I reach the "threshold" of knowledge acceptable for user groups or chat rooms, I tend to not want to go back based on my early experiences. Perhaps it would be helpful to provide some alternative user groups or chat rooms for true beginners? Just an idea. I hope my comments are somewhat constructive, because that is my only intention. Aaron On Jan 29, 12:40 am, Malcolm Tredinnickwrote: > On Wed, 2009-01-28 at 05:53 -0800, ajlozier wrote: > > Thank you for responding. > > > Yeah I was starting to figure out just what you're saying, that I > > can't access the functions of a class within the class definition > > itself. This is also true in PHP. In this case, if I were writing in > > PHP I would do something like this: > > > function __construct(){ > > parent::__construct(); //because this is a subclass > > $this->classification = $this->getClassificationTree(); > > } > > > I figured I should probably do a similar thing here using the __init__ > > function, but I have run into numerous problems. It seems I am having > > trouble matching up the exact parameters of the class this one is > > inheriting from. > > I don't understand what this means. Can you be a bit more specific? > > There are examples all over the Django code (including > ModelFormBase.__init__) or __init__ methods calling their parent class's > __init__ method. Search for calls to "super()", which is the standard > way to call the next method in the name resolution order. > > > Believe it or not I can't even seem to find an API > > page explaining all of the parameters, methods and properties of > > ModelForm. > > I have gone back to the source but so far it hasn't helped > > me. > > Then "API documentation" wouldn't really add much value; it would simply > repeat the code, in effect (rewriting everything in English again). We > have documentation describing standard ModelForm usage and we prefer > holistic descriptions to API dumps. The source isn't particularly > complicated: everything inherits from BaseModelForm and the __init__ > method's parameters are named for their purpose and they have the same > names as the parameters in BaseForm. > > Hopefully (and necessarily, really) before diving into creating > derivatives of ModelForm, one has a good general understanding of how > Django
Re: #7210 - F() Query Expressions
On Fri, Jan 30, 2009 at 2:47 AM, koenbwrote: > > This is really great! Thanks all for the good work. > > Just curious, has there been any work done to make this also work for > dates ? > > like in > > longevents = Event.objects.filter(enddate__gte=F('startdate')+10) As committed, the expressions framework is fairly dumb - it is really just a way to do two things: 1) Expand Django-style field references into column names (and joins if required) 2) Turn Python expression trees into SQL expression trees. This means that the operations that are allowed depend somewhat on the database in use. For example, on MySQL, you can perform mod operations on floats; under Postgres, you can't. Constants in expressions are rendered as-is, so whether dates are allowed depends on what your database allows. From some quick tests, date + integer works on SQLite and MySQL -- or, at least, doesn't throw an error. I haven't confirmed that the answer it gives is actually meaningful. Postgres complains with an error "operator does not exist: timestamp with time zone + integer". However, I'm certainly interested in entertaining any modification to support more interesting expressions - for example, converting the expression "F('date') + timedelta(days=3)" into meaningful SQL. Patches welcome. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: order by count
The problem with the sorting method is that I think it will take to much time. I would like if it could happen as part of the query. "operator module to get attributes of the object(s) in your QuerySet", I'm not sure I know how to do this. I have tried writing it as SQL with cursor: cursor.execute("SELECT word, ref_id, COUNT(ref_id) c FROM search_searchword WHERE word LIKE %s OR word=%s GROUP BY ref_id ORDER BY c desc",["%est%", "test2sf"]) #"SELECT foo FROM bar WHERE baz = %s", [self.word]) It works byt then I have the problem that ref_id is a foreign key and I would like to have the objects i points to a long as well. It looks like it is by far easier to find some way to it in Django Brandon Taylor wrote: > > > Hello, > > You can use the sorted() function in Python to order any iterable. It > asks for a key to order by, which can be a lambda, or you could use > the operator module to get attributes of the object(s) in your > QuerySet object to provide the key. > > My $0.02, > Brandon > > On Jan 29, 12:38 pm, lollerikkenwrote: >> Hello, sorry about my English, but I hope that it is understandable >> >> I am having some trouble using order_by with Django. >> >> I think it would be easier to explain what I want with an example: >> >> fx if I have this table: >> >> key ref >> 1 a >> 2 g >> 3 a >> 4 c >> 5 g >> 6 g >> >> I would like to sort it like this: >> >> key ref >> 2 g >> 5 g >> 6 g >> 1 a >> 3 a >> 4 c >> >> because there is the highest count of g's etc. >> >> My google search suggested that I should use something called annotate >> combined with count, but it does not work. >> I have tried something like: >> table.objects.values('key', >> 'ref').annotate(nr_ref=Count('ref')).order_by('nr_ref') >> but without any luck. >> -- >> View this message in >> context:http://www.nabble.com/order-by-count-tp21732508p21732508.html >> Sent from the django-users mailing list archive at Nabble.com. > > > > -- View this message in context: http://www.nabble.com/order-by-count-tp21732508p21738150.html Sent from the django-users mailing list archive at Nabble.com. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: ContentTypes and fixtures
this has bitten me too recently. in general I'm moving away from fixtures. they are breakable, they suffer when the codebase is refactored. particularily for tests I no longer use fixtures. I would suggest trying the dump-to–python-code method ideally there should be a away to dump a group (or all) objects into some data structure where all foreign keys are referenced only internally through some lookup table (that is saved with the objects). then when loading the structure the objects would be given homes in the database and the foreign keys would all get resolved into real-world db ids. there would have to then be a part of the structure that resolved foreign key ids by a lookup in the host environment where the structure is being installed (eg looking up the content ids) the other use for this system would be federating data from site to site. felix :crucial-systems.com On Thu, Jan 29, 2009 at 12:15 AM, Russell Keith-Magee < freakboy3...@gmail.com> wrote: > > On Thu, Jan 29, 2009 at 7:36 AM, Oliver Beattie> wrote: > > > > How can I be sure that the ContentType IDs are always constant, and > > therefore my data in fixtures is guaranteed to always point to the > > right object? > > Oliver, meet ticket #7052. Ticket #7052, meet Oliver :-) > > This is an annoying bug that I have wanted to address for a while. The > ticket describes an approach that I believe will work, but doesn't > contain a patch. On IRC a few days back, Eric Holscher mentioned that > he had a nasty hack that implemented a fix for this. I don't know how > far that hack has gone, or if he will be willing to share code. > > The best workaround that I can suggest is to include your ContentTypes > in your fixtures. They are dumpable objects, just like everything else > in Django. If your fixture contains the content types, it doesn't > matter what primary key values are automatically created, because they > will be overwritten by the fixture. You shouldn't get any duplicate > primary key errors because the fixtures framework overwrites existing > objects with the same primary key. The only time you need to be > careful is when you start adding new models, and new content types are > created - if you don't update your fixtures, you could get some > interesting side effects. > > Yours, > Russ Magee %-) > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Apps and static/media files
I'm having a situation in which two of my reusable apps both use FCKeditor in their admin interface. Since both of them require FCKeditor library files, I'm confused which one should provide them? Both? How? What is the idiomatic/standard way of doing this? Should I instead have them both just assume "{{ MEDIA_URL }}lib/fckeditor/ fckeditor.js" exists and document this requirement/assumption in the docs of both apps? (This is a general media/static files question, I'm just bringing FCKeditor as an example.) Erik --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Improving the response time in Django Admin
On Thu, Jan 29, 2009 at 5:49 PM, Tipanwrote: > I'll go ahead as planned on the Django update and see if this delivers > any improvements. With regards to your suggestion of using the raw id > field, is this a Django option, or did you mean changing the FK to > using a simple ID field. I've been through the docs and can't see any > reference to a raw_id option, although recall seeing it mentioned on > some occasion whilst trawling. If an option, can you give me a link? > Assuming you're looking for the 1.0 doc: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#raw-id-fields Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Improving the response time in Django Admin
> > Without specifics, it's a little difficult to say for certain, but one > of the reasons for the switch to newforms and newforms-admin was to > eliminate some very expensive querying behavior in the manipulators > behind forms. This wasn't a matter of one big query that was expensive > - but you could easily end up with a very large number of very small > queries. As your user base expands, it's entirely possible that the > flood of little queries is adding up and slowing down the site. > > The other obvious place to look is where Karen noted - Foreign keys > with very large selection sets. The raw id field option is one way to > address this; another approach is to write a custom widget that > doesn't try to load the entire selection set. > Thanks, despite my lack of detail this is a good pointer to identify what to change. I have several tables which use reference an FK on a larger table. Some of the slower ones don't however, so I'll need to delve a bit further to see what might be causing it. I'll go ahead as planned on the Django update and see if this delivers any improvements. With regards to your suggestion of using the raw id field, is this a Django option, or did you mean changing the FK to using a simple ID field. I've been through the docs and can't see any reference to a raw_id option, although recall seeing it mentioned on some occasion whilst trawling. If an option, can you give me a link? Thanks and regards, Tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
FormWizard accessing previous fields data
Hi all, say i have a FormWizard of 5 steps and at the last step i want to display a summary of the submitted data how do i access the value of a field that was in the form at step 1? example: class Step1(Form): foo = CharField() bar = CharField() So at step 5 i'd like to display the value of Step1.foo. Thanks, Lorenzo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
guidance on serialization
Hello all. Say I have some models like these: class Image(models.Model): file = models.ImageField(upload_to=get_image_path) class Line(models.Model): image = models.ForeignKey(Image) color = models.CharField(max_length=20) width = models.IntegerField() class Point(models.Model): line = models.ForeignKey(Line) ordering = models.IntegerField() x = models.IntegerField() y = models.IntegerField() And I want to load an image and all its lines into the interface, add and remove lines, and then send it back to the controller. What's the django-ish way to serialize data like this? The default serializers doesn't seem to do relationships. I saw discussion[1] of one that does foreign keys but it seems to be going to in the opposite direction I want (and it doesn't deserialize yet?). Stepping back, is this sort of thing that you'd be expected to do with a custom serializer? Or is it better to just serialize each set of data separately and save them separately. I started by using simplejson directly but then was wondering about the built-in serialization code in Django. Disclaimer: I'm starting on my first real Django project so I still have limited knowledge the framework. :) I'm using 1.0.2. Thanks! Jason [1] http://groups.google.com/group/django-users/browse_thread/thread/c930cf920e726bbd/4faa358b8c91365d --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Expression Engine for Django?
On Thu Jan 29 13:49 , "maltebeckm...@mac.com" sent: > >I am an Expression Engine (CMS) fan who recently got convinced that >Python is way cooler than PHP. Problem is that Expression Engine is >written in PHP. > >Is there an Expression Engine for Django, i.e. an installation package >that can be deployed by people with less development experience? > >I am bringing this up because I love what I have seen of Django so >far! Thanks for reading! > Switching this conversation to the users list where it belongs. There is no Expression Engine interface for Django that I am aware of and a quick google search does not show anything. Of course, nothing is stopping someone from duplicating the Expression Engine functionality in Python for Django (-: There are quite a few blogs powered by Django these days and writing your own is a great learning opportunity --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Finding and Displaying the Object that a Comment is Created On
On Jan 29, 3:48 pm, "dave.mer...@gmail.com"wrote: > This si a somewhat nooby question. > > I have a comment. I want to display the post title for the > comment.object_id. > > In the template I have been trying things like comment.post.title, but > that is not working. > > I think it is due to the fact that Comments use a generic foreign key. > So... how do I do this? > > Any references? > > Lemme know. > Dave comment.content_object.title should get what you want --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: order by count
Hello, You can use the sorted() function in Python to order any iterable. It asks for a key to order by, which can be a lambda, or you could use the operator module to get attributes of the object(s) in your QuerySet object to provide the key. My $0.02, Brandon On Jan 29, 12:38 pm, lollerikkenwrote: > Hello, sorry about my English, but I hope that it is understandable > > I am having some trouble using order_by with Django. > > I think it would be easier to explain what I want with an example: > > fx if I have this table: > > key ref > 1 a > 2 g > 3 a > 4 c > 5 g > 6 g > > I would like to sort it like this: > > key ref > 2 g > 5 g > 6 g > 1 a > 3 a > 4 c > > because there is the highest count of g's etc. > > My google search suggested that I should use something called annotate > combined with count, but it does not work. > I have tried something like: > table.objects.values('key', > 'ref').annotate(nr_ref=Count('ref')).order_by('nr_ref') > but without any luck. > -- > View this message in > context:http://www.nabble.com/order-by-count-tp21732508p21732508.html > Sent from the django-users mailing list archive at Nabble.com. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Finding and Displaying the Object that a Comment is Created On
This si a somewhat nooby question. I have a comment. I want to display the post title for the comment.object_id. In the template I have been trying things like comment.post.title, but that is not working. I think it is due to the fact that Comments use a generic foreign key. So... how do I do this? Any references? Lemme know. Dave --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
reason for missing readline() in uploaded files?
I'm trying to validate an uploaded csv file, so I want to read the first line of text and if it's not the right format, send an error message. Unfortunately, neither InMemoryUploadedFile nor TemporaryUploadedFile have the readline() method. Was that an oversight (in which case I'll create a two-line patch and submit it--both StringIO and temp files support the method) or a design decision with a good reason? Thanks, Todd --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Three table Lookup Question
I'm not sure I understand what you're asking, but projs = Project.objects.filter(campaign__industry=x) where x is one of 1-6 should do what you want, I think. Is that what you were asking? On Thu, Jan 29, 2009 at 9:54 AM, Kylewrote: > > Hello! > > I am trying to get a list of "Projects" based on certain "Industry". > (My naming convention, not django's) > > My models look like this: > http://dpaste.com/114308/ > > "Project" has a foreign key to "Campaign". > > "Industry" also has a foreign key to "Campaign". > > Does it matter if both relationships are pointing to the center model > in the data route I am trying to setup? Like this: > > Project -> Campaign <- Industry > > If Industry = 3, and a handful of Campaigns are returned, I would like > a list of all the Projects contained in each of the Campaigns > returned. > > How do I do this with django models? > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Cron Job Question
Chris wrote: > I have a python / django script that I have written which will be > used as a cron. Basically this script goes out to my database and gets > rows from a given table and performs a specific task then deletes the > row once finished. What I would like to do is have multiple instances > of this script running to check for new additions to this table every > 15 minutes or so. I am not sure how I can divide up the work to be > processed among all running scripts with out having issues. > I'm curious: why do you need multiple instances? The only reason I can think of is that you need multiple machines to get the tasks done in a timely manner. Is this the case? The model that we use for a similar setup is the script will check the database, process ALL unprocessed rows (no wait in between jobs), and then when it's done, it waits a few seconds and checks again. This works very well in production. Most of the time only one or two jobs will be inserted at a time, but occasionally several hundreds or thousands of jobs will be inserted. One instance of the worker script handles this very well. We moved away from the cron job, and implemented a simple daemon process. If you really really really need the multiple instances, you could have a worker script that launches the jobs one at a time, and will only spawn as many as you need at once. I'd also suggest looking into database locking or transactions if you want to have multiple scripts with their fingers in the same table. Cheers! Jeff Anderson signature.asc Description: OpenPGP digital signature
Re: Custom authentication backend and User passwords
Thanks Malcolm. For anyone interested in this topic, I have created a snippet with my solution: http://www.djangosnippets.org/snippets/1301/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Cron Job Question
I have a python / django script that I have written which will be used as a cron. Basically this script goes out to my database and gets rows from a given table and performs a specific task then deletes the row once finished. What I would like to do is have multiple instances of this script running to check for new additions to this table every 15 minutes or so. I am not sure how I can divide up the work to be processed among all running scripts with out having issues. Currently the script does an .objects.all() call and runs through the entire list but as mentioned would like to find a way to divide this up and with out another instance trying to process a row that is being processed by another instance. The main question would be how I can tell the script to not process a given row b/c another instance of the script is currently processing the row or is in its queue to be processed. It would also be nice to be to have the ability to add or remove instances of the script in times when the table is more or less full with rows to process. Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Any way to NOT escape a percent sign using 'contains'?
According to the docs, when using 'contains' in filter() a percent sign or underscore is automatically escaped. However, in my case I want the resulting SQL to use the percent sign. I know 'contains' will fill in the outside percent signs, but it escapes the percent sign in my string. So that calling: Entry.objects.filter(headline__contains='a%b') will result in: SELECT ... WHERE headline LIKE '%a\%b%'; but I want it to be this instead: SELECT ... WHERE headline LIKE '%a%b%'; This there an easy way to do this? I could use regexp, but I didn't want people to know that they would have to use "a.*b" instead of "a*b", just trying to make it simplier for myself and the people using the system. -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
order by count
Hello, sorry about my English, but I hope that it is understandable I am having some trouble using order_by with Django. I think it would be easier to explain what I want with an example: fx if I have this table: key ref 1 a 2 g 3 a 4 c 5 g 6 g I would like to sort it like this: key ref 2 g 5 g 6 g 1 a 3 a 4 c because there is the highest count of g's etc. My google search suggested that I should use something called annotate combined with count, but it does not work. I have tried something like: table.objects.values('key', 'ref').annotate(nr_ref=Count('ref')).order_by('nr_ref') but without any luck. -- View this message in context: http://www.nabble.com/order-by-count-tp21732508p21732508.html Sent from the django-users mailing list archive at Nabble.com. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Custom Template Tag - Passing variable for use in tag processing
This is the final code which works in case it helps anyone else. Thanks again. In the template: {% page_links category %} In templatetags file @register.tag(name="page_links") def get_page_links(parser,token): tag_name, category = token.contents.split() return PageLink(category) class PageLink(template.Node): def __init__(self, category): self.category = template.Variable(category) def render(self, context): cat = self.category.resolve(context) if cat=='business': pages=BusinessPage.objects.filter (is_live=True).select_related().order_by('order') elif cat=='community': pages=CommunityPage.objects.filter (is_live=True).select_related().order_by('order') elif cat=='tourism': pages=TourismPage.objects.filter (is_live=True).select_related().order_by('order') else: pages = False context['pages'] = pages return '' On Jan 29, 3:22 pm, phoebebrightwrote: > You understood perfectly. It was just another case of my not > understanding the documentation. Your explanation makes perfect > sense. > > Many thanks. > > On Jan 27, 6:45 pm, Eric Abrahamsen wrote: > > > On Jan 28, 2009, at 1:52 AM, phoebebright wrote: > > > > I have duplicated as best I can the processing for handling variables > > > incustomtemplatetagsmentioned in an earlier post but it's not > > > working for me as I need the value of the variable before I parse it. > > > Is there another way of making the variable available? > > > > The tag is being called from the tempalte with: > > > > {% page_links "category" %} > > > > Where category is being passed into thetemplatefrom a view. (also > > > tried "{{category}}" and {{category}} and category) > > > > I want to use the value of category to determine which list of pages > > > to return. > > > > I KNOW THIS DOESN"T WORK: > > > > @register.tag(name="page_links") > > > def get_page_links(parser,token): > > > tag_name, cat = token.contents.split() > > > return PageLink(cat[1:-1]) > > > > class PageLink(template.Node): > > > > def __init__(self, cat): > > > > cat=template.Variable(cat) > > > print cat <- outputs category > > > if cat=='business': > > > pages=BusinessPage.objects.filter > > > (is_live=True).select_related().order_by('order') > > > elif cat=='community': > > > pages=CommunityPage.objects.filter > > > (is_live=True).select_related().order_by('order') > > > elif cat=='tourism': > > > pages=TourismPage.objects.filter > > > (is_live=True).select_related().order_by('order') > > > > else: > > > pages = False > > > > self.pages = pages > > > > def render(self, context): > > > context['pages'] = self.pages > > > > return '' > > > I might be missing something you're trying to do here, but the usual > > method for resolving a variable in acustomtemplatetag is to first > > put it into the tag (without quotes) like so: > > {% page_links category %} > > > Then attach that to your PageLink node in its __init__ method as a > > Variable: > > self.cat =template.Variable(cat) > > > Then inside the render method first resolve it: > > category = self.cat.resolve(context) > > > and then check the value of category against your various models. That > > all has to be done in render, not __init__, because context is only > > available in render. > > > This is all straight out of the > > docs:http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#pass... > > > Apologies in advance if I've misunderstood what you're trying to do... > > > Eric > > > > This code works fine as long as I call it like this: > > > > {% page_links "business" %} > > > > @register.tag(name="page_links") > > > def get_page_links(parser,token): > > > > tag_name, cat = token.contents.split() > > > cat = cat[1:-1] > > > > if cat=='business': > > > pages=BusinessPage.objects.filter > > > (is_live=True).select_related().order_by('order') > > > elif cat=='community': > > > pages=CommunityPage.objects.filter > > > (is_live=True).select_related().order_by('order') > > > elif cat=='tourism': > > > pages=TourismPage.objects.filter > > > (is_live=True).select_related().order_by('order') > > > else: > > > pages = False > > > > return PageLink(pages) > > > > class PageLink(template.Node): > > > > def __init__(self, pages): > > > self.pages = pages > > > > def render(self, context): > > > context['pages'] = self.pages > > > > return '' > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from
Re: #7210 - F() Query Expressions
This is really great! Thanks all for the good work. Just curious, has there been any work done to make this also work for dates ? like in longevents = Event.objects.filter(enddate__gte=F('startdate')+10) or something like that ? Koen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can I control contents of SELECT in queryset?
That's an interesting post but I havn't managed to get it to solve my problem because I'm looking for a list of all categories and that method using FOO_set only seems to work on a single object (get). Also tried the raw sql method but I get an SQL error (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''business' td, town_subcategory sc WHERE td.cat_id = sc.id' at line 1") Even though if I run the sql manually it is fine. from django.db import connection cursor = connection.cursor() cursor.execute("SELECT DISTINCT sc.name, sc.id FROM town_%s td, town_subcategory sc WHERE td.cat_id = sc.id", [for_cat]) subcats = cursor.fetchall() Any further thoughts most welcome! On Jan 29, 3:48 pm, Almost Georgewrote: > On Jan 29, 8:44 am, phoebebright wrote: > > > > > I want a distinct list of all the 'cat__names' that exist in > > Subcategory and have at least one entry in Business (Business is a > > subclass of model Directory which might be the problem) > > > dir_query = Business.objects.all().select_related().distinct() > > ... > > subcats = dir_query.values('cat__name','cat').select_related().distinct > > () > > > But the SQL this generates has an additional field in theSELECT > > statement which means the DISTINCT does not have the effect I want and > > selects all entries. > > >SELECTDISTINCT `town_subcategory`.`name`, `town_business`.`cat_id`, > > `town_directory`.`name` > > FROM `town_business` > > INNER JOIN `town_subcategory` ON (`town_business`.`cat_id` = > > `town_subcategory`.`id`) > > INNER JOIN `town_directory` ON (`town_business`.`directory_ptr_id` = > > `town_directory`.`id`) > > ORDER BY `town_directory`.`name` ASC > > > Is there some way of forcing the fields in theselectstatement > > without having to write the whole SQL in raw format? Or another way > > of writing the query? > > Have you tried any of the methods listed in this > article?http://thisweekindjango.com/articles/2007/dec/21/retrieving-selective... > ( Retrieving Selective Fields with Django ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Sending emails through Microsoft Exchange in django?
Hi all, I was just wondering if anyone has tried sending mail through Microsoft exchange. What information do I need, and will it work with django's smtp functions? Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: media files apache/modpython windows
Ok, I think I finally got it! In order to use my css template as a django inherited base.html(which is under folder-template) I have to place my html(ex. index.html) pages under the same folder "template", which is specified as a directory path in the settings.py file under TEMPLATE_DIRS: 'C:/folder/subfolder/templates', However, if I want any CSS or images to be used in index.html I must place them in a separate folder in a directory called site_media. (the media folder actually refers to the css for my admin files). For media and site_media to work I need to add the following to my settings.py file: For the site css and images: MEDIA_ROOT = 'C:/folder/subfolder/site_media' MEDIA_URL = 'http://localhost/site_media/' For the admin css: ADMIN_MEDIA_PREFIX = 'http://localhost/media/' But the media(admin css) and site_media(my css and images) won't work under apache until I add the following to the http.conf file: ServerName http://localhost Alias /media C:/djangopath/folders/admin/media SetHandler python-program PythonHandler django.core.handlers.modpython PythonDebug On Allow from all SetHandler None SetHandler None But, one more complication occurs. When I select any link under the template folder (which is supported by the django server, I also must specify that link in the URL.py and View.py. That link looks like this: http://localhost/index; >index file URL: (r'^index/$', 'index'), VIEW: def index(request): return render_to_response('index.html', RequestContext(request)) Any link selected from the site_media folder is controlled by Apache, so I don't need to put anything in URL.py or View.py. That link looks like this: http://localhost/site_media/images/image.gif"/> All the above now works well for me and I hope that it is the simplest configuration. I am placing all this code here with the sincere hope that someone else will find it useful, because no matter how many times I read the django documentation it doesn't explain any of the above very well. I am a PHP programmer, so maybe my previous experience tainted me from looking at the django configuration differently than how I would have built a web page in PHP under Apache. Thank you for all your help and please comment if I am incorrect or if the configuration could be made easier. May --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Changing comments preview form
Am 29.01.2009 um 01:59 schrieb Malcolm Tredinnick: > > On Wed, 2009-01-28 at 19:24 +0100, Florian Lindner wrote: >> >> Am 28.01.2009 um 05:19 schrieb Malcolm Tredinnick: >> >>> >>> On Tue, 2009-01-27 at 20:11 +0100, Florian Lindner wrote: Hello, I'm playing around with the contrib.comments framework. I want to change the preview form. For that I've copied preview.html to xgm/ Blog/ templates/comments (xgm is my project, Blog is app). My template loaders are: TEMPLATE_LOADERS = ( 'django.template.loaders.app_directories.load_template_source', 'django.template.loaders.filesystem.load_template_source', ) But modification I make to the preview.html in my app dir does not seem to be noticed. >>> >>> >>> For comments, if you're only wanting to change the preview form >>> for a >>> particular model or particular application, note that the template >>> loaded for preview is not comments/preview.html, always. That is the >>> name that is loaded is all else fails. However, the application >>> first >>> looks for >>> >>> comments/__preview.html >>> comments/_preview.html >>> >>> where is the name of the application and is the name >>> of >>> the model to which the comment is attached. If either of those >>> templates >>> are found, they are used for preference. So for an app-specific >>> customisation for an app called "foo", say, you could create >>> >>> comments/foo_preview.html >>> >>> in the foo/templates/ directory and it will be loaded for the >>> preview. >> >> Hi! >> >> Thanks for your answer. I decided to take the latter way. Thus I've >> copied preview.html to Blog_Entry_preview.html in the templates/ >> comments/ directory and it worked perfectly. I tried the same copying >> with the posted.html to Blog_Entry_posted.html but this does not >> work. >> My Blog_Entry_posted.html simply seems to be ignored. >> >> Any idea what I could have made wrong? I've double checked >> everything... > > So, for the future: It took about 30 seconds to grep through the > comments source (in django.contrib.comments) to find where posted.html > is used and see that it's doesn't allow that customisation (which is > also how I found that preview.html is the third of three things > checked). > > Remember, Django is in Python. The source is your friend. Ok, you're right. I've searched through Google but didn't got the idea to grep the code. My apologies. Is there any reason why this lookup is not implemented for all comments templates? If not I'll try to create a patch and commit into the ticket system. Regards, Florian. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: views, templates, render and groups
ok... i'm trying to use exclude in the query set to get this to work. I'm not entirely sure how my logic should go though... especially since i would be comparing to lists that would result in <> not being usable... since a user and a group won't contain the same set of groups. is it possible to do use a boolean? i realize list.index(x) returns an error, not a -1 as in java... so how would i get about including a forumgroup.index(User.groups) > -1 of course... that only works if there is one group assigned to the user... i would have to check each group... I'm sure this is a simple logic issue... but i can't seem to figure out what i'd need to do On Jan 19, 1:50 pm, garagefanwrote: > pretty vague title i know... > > Can I return a query set via foo.object.filter() where in filter i > check a manytomany field in foo against the group field for a user? > > I guess a way to use a group as a permission? > > IE: An article that would normally appear with a ton of other > articles, in a ManyToMany field tied to groups has been set to Group1. > Now a handful of users are in Group1 and that article is only supposed > to be visible to those people, as well as the other non-group assigned > articles in the list. > > I'd like to take care of this in the views in the render for the > template so that only the objects that can be viewed are passed > through. It seems that permissions are set up by django based on the > models themselves, and i haven't seen anything on creating custom > permissions for groups themselves. So any of the permission check > functions would not work. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: can i use models like that??
well thank you, what do you think about this one? is that possible? class Product(models.Model): name = models.CharField(max_length=50) slug = models.SlugField() preview_animation = models.ImageField(upload_to = "animations") class Game(Product) another_properties = CharField.. ... ... -- Mirat Can Bayrak--~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: links in table - one for URL, one not
Thanks all! I needed to put the curly brackets around the website variable. Dumb mistake on my part. It works now! Thanks! {{ researchproject.institution| > > safe }} On Jan 28, 2:15 pm, Karen Traceywrote: > On Wed, Jan 28, 2009 at 4:28 PM, May wrote: > > > Hello, > > > I am extracting data from a postgres table into an html table. I have > > two columns. > > > The user can select the link in this column, the link will be returned > > through the URL and view.py to extract more information from the > > postgres table: > > {{ researchproject.restitle| > > safe }} > > > This column will have the http:// address for an institution, which I > > would like the user to be able to directly link to an external > > website. My error is that django won't allow me to directly link to > > an external website without first assigning a URL and a view. How can > > I override django on this? > > > {{ researchproject.institution| > > safe }} > > > Thanks for any help. > > What do you mean "django won't allow me to directly link to an external > website"? Django doesn't care what links you include on your pages. In the > example you give you are specifying "researchproject.website" as an href. > That's a relative link, so when you click on it the browser will request the > linked page from the same server where it got the page containing the link. > If you want to link to an entirely different site, you need to specify your > href value to reflect that, something more like: > > http://researchproject.website;>{{ researchproject.institution > > }} > > Karen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Can I control contents of SELECT in queryset?
On Jan 29, 8:44 am, phoebebrightwrote: > I want a distinct list of all the 'cat__names' that exist in > Subcategory and have at least one entry in Business (Business is a > subclass of model Directory which might be the problem) > > dir_query = Business.objects.all().select_related().distinct() > ... > subcats = dir_query.values('cat__name','cat').select_related().distinct > () > > But the SQL this generates has an additional field in the SELECT > statement which means the DISTINCT does not have the effect I want and > selects all entries. > > SELECT DISTINCT `town_subcategory`.`name`, `town_business`.`cat_id`, > `town_directory`.`name` > FROM `town_business` > INNER JOIN `town_subcategory` ON (`town_business`.`cat_id` = > `town_subcategory`.`id`) > INNER JOIN `town_directory` ON (`town_business`.`directory_ptr_id` = > `town_directory`.`id`) > ORDER BY `town_directory`.`name` ASC > > Is there some way of forcing the fields in the select statement > without having to write the whole SQL in raw format? Or another way > of writing the query? Have you tried any of the methods listed in this article? http://thisweekindjango.com/articles/2007/dec/21/retrieving-selective-fields-django/ ( Retrieving Selective Fields with Django ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
middleware response processing always occurs
We recently uncovered a bug in our code, which was pretty confusing, and is explainable only via the fine-print of http://docs.djangoproject.com/en/dev/topics/http/middleware/ -- and reading through the Django source. So I thought I'd share, and maybe a Django developer might comment on whether the current behaviour is really desirable, and if so perhaps consider improving the docs. We have some Middleware that updates the user's session, from a process_response method. Sometimes this would fail, because the request object had no session. It turns out this would happen because the Common middleware had issued a redirect (specifically, APPEND_SLASH was redirecting us to correct the view's URL). In a case like this, the current behaviour is not like the 'onion' as illustrated in the docs, because whilst the redirect meant that *only* the Common middleware had its process_request function executed, every loaded middleware's process_response is executed. (This is mentioned in the docs, it turns out, in the process_request section but not in the process_response section.) What this means is that even though it seems, and is the case 99% of the time, that middleware listed later can rely totally on middleware further up the list (i.e. the 'onion' model), this is in fact not the case, for processing responses. So response processing code is either subject to rare bugs, or has to contain extra checks to make sure of its preconditions (in our case a check for hasattr(request, 'session') ). Personally I think this is confusing enough that it would be better if the program logic could be changed, so that later-listed middleware would definitely only either run, or not run, depending on whether the earlier middleware allows the request to proceed or not. But I guess such a change could break existing code, so at the very least the docs could use a bit more explanation and or highlighting in bold! thanks George Lund --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Custom Template Tag - Passing variable for use in tag processing
You understood perfectly. It was just another case of my not understanding the documentation. Your explanation makes perfect sense. Many thanks. On Jan 27, 6:45 pm, Eric Abrahamsenwrote: > On Jan 28, 2009, at 1:52 AM, phoebebright wrote: > > > > > > > I have duplicated as best I can the processing for handling variables > > incustomtemplatetagsmentioned in an earlier post but it's not > > working for me as I need the value of the variable before I parse it. > > Is there another way of making the variable available? > > > The tag is being called from the tempalte with: > > > {% page_links "category" %} > > > Where category is being passed into thetemplatefrom a view. (also > > tried "{{category}}" and {{category}} and category) > > > I want to use the value of category to determine which list of pages > > to return. > > > I KNOW THIS DOESN"T WORK: > > > @register.tag(name="page_links") > > def get_page_links(parser,token): > > tag_name, cat = token.contents.split() > > return PageLink(cat[1:-1]) > > > class PageLink(template.Node): > > > def __init__(self, cat): > > > cat=template.Variable(cat) > > print cat <- outputs category > > if cat=='business': > > pages=BusinessPage.objects.filter > > (is_live=True).select_related().order_by('order') > > elif cat=='community': > > pages=CommunityPage.objects.filter > > (is_live=True).select_related().order_by('order') > > elif cat=='tourism': > > pages=TourismPage.objects.filter > > (is_live=True).select_related().order_by('order') > > > else: > > pages = False > > > self.pages = pages > > > def render(self, context): > > context['pages'] = self.pages > > > return '' > > I might be missing something you're trying to do here, but the usual > method for resolving a variable in acustomtemplatetag is to first > put it into the tag (without quotes) like so: > {% page_links category %} > > Then attach that to your PageLink node in its __init__ method as a > Variable: > self.cat =template.Variable(cat) > > Then inside the render method first resolve it: > category = self.cat.resolve(context) > > and then check the value of category against your various models. That > all has to be done in render, not __init__, because context is only > available in render. > > This is all straight out of the > docs:http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#pass... > > Apologies in advance if I've misunderstood what you're trying to do... > > Eric > > > > > This code works fine as long as I call it like this: > > > {% page_links "business" %} > > > @register.tag(name="page_links") > > def get_page_links(parser,token): > > > tag_name, cat = token.contents.split() > > cat = cat[1:-1] > > > if cat=='business': > > pages=BusinessPage.objects.filter > > (is_live=True).select_related().order_by('order') > > elif cat=='community': > > pages=CommunityPage.objects.filter > > (is_live=True).select_related().order_by('order') > > elif cat=='tourism': > > pages=TourismPage.objects.filter > > (is_live=True).select_related().order_by('order') > > else: > > pages = False > > > return PageLink(pages) > > > class PageLink(template.Node): > > > def __init__(self, pages): > > self.pages = pages > > > def render(self, context): > > context['pages'] = self.pages > > > return '' > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Three table Lookup Question
Hello! I am trying to get a list of "Projects" based on certain "Industry". (My naming convention, not django's) My models look like this: http://dpaste.com/114308/ "Project" has a foreign key to "Campaign". "Industry" also has a foreign key to "Campaign". Does it matter if both relationships are pointing to the center model in the data route I am trying to setup? Like this: Project -> Campaign <- Industry If Industry = 3, and a handful of Campaigns are returned, I would like a list of all the Projects contained in each of the Campaigns returned. How do I do this with django models? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Any django users in Malaysia/Singapore
Hi, I'm in Singapore. I'm building a django/satchmo site right now. I have worked on about ten Django sites in the past, and for a Singapore client in particular we just completed http://www.asiansecurity.org/ Good to know there are other Django users here! Cheers, Arthur On Jan 29, 2:00 pm, Kelvin Queewrote: > From Singapore here. We have at least 1 Django expert in our company. :) > > Kelvin Quee > k...@kquee.com > +65 9177 3635 > > http://kquee.com > > 2009/1/29 ycloh : > > > > > Yeah, would have been nice if there was some sharing, which is why i > > wanted to know if there were users in KL or Sin. Would be nice to at > > least arrange some sort of get together/ teh tarik session, if there > > were enough developers around. > > > On Jan 29, 9:15 am, Bond Lim wrote: > >> Hi, I am from Malaysia and currently using django. Too bad is that in > >> Malaysia, we do not have any python or django conference, > > >> On Wed, Jan 28, 2009 at 04:58:09PM -0800, ycloh wrote: > > >> > Hi all, just wondering if there are many django users in this part of > >> > this world and how is django being used. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Can I control contents of SELECT in queryset?
I want a distinct list of all the 'cat__names' that exist in Subcategory and have at least one entry in Business (Business is a subclass of model Directory which might be the problem) dir_query = Business.objects.all().select_related().distinct() ... subcats = dir_query.values('cat__name','cat').select_related().distinct () But the SQL this generates has an additional field in the SELECT statement which means the DISTINCT does not have the effect I want and selects all entries. SELECT DISTINCT `town_subcategory`.`name`, `town_business`.`cat_id`, `town_directory`.`name` FROM `town_business` INNER JOIN `town_subcategory` ON (`town_business`.`cat_id` = `town_subcategory`.`id`) INNER JOIN `town_directory` ON (`town_business`.`directory_ptr_id` = `town_directory`.`id`) ORDER BY `town_directory`.`name` ASC Is there some way of forcing the fields in the select statement without having to write the whole SQL in raw format? Or another way of writing the query? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django Forms in HTML 4.01 Strict
On Jan 29, 2:18 pm, Gertjan Kleinwrote: > This payment thing comes up regularly here, and pollutes the discussion. > I have been using Django for a while, and found it to have good things > and downsides (both IMHO). I have not even critisized Django here (yet > ;)), just expressed mild curiousity. I don't think I've given you reason > to bring up that you're not payed for your work on Django. Off-topic: For what it's worth I agree with you. I've lost track of the number of times i've found bugs in open source software and been not-so-subtly told to contribute the fix myself. Or asked about something that I think should be included and been told to write it myself. As a consumer of software libraries it is not my job to fix them, maybe there will come a time when I choose to spend some time contributing back to the projects, but there is a lot of overhead involve in learning enough of how a library works to write patches and not everyone can spare this. Additionally some of us simply aren't smart enough to fix/add features we want. Your reasoning for wanting this functionality is reasonable, as is Malcom's explanation for why it has yet to be done (nobody has agreed on the best way to do it) Regards, Andrew Ingram --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Getting Logged in User with Test Client
Malcolm thanks for the feedback and your right, I agree with you that the client should not know about the user. Vitaly Babiy 2009/1/26 Malcolm Tredinnick> > On Sat, 2009-01-24 at 12:14 -0500, Vitaly Babiy wrote: > > Yes either way would work I was just wondering if there was a more > > cleaner way of doing so. > > Then you're going to have to define what "cleaner" means from your > persepctive. What could be cleaner that simply get()-ing the right model > based on the unique piece of identifying information (the username)? > It's one line of code. > > The browser-emulating side (self.client) doesn't and shouldn't care > about that, since it's the browser-side of the test, not the > server-side. > > Regards, > Malcolm > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django Forms in HTML 4.01 Strict
Malcolm Tredinnick wrote: >On Wed, 2009-01-28 at 14:33 +0100, Gertjan Klein wrote: >> Malcolm Tredinnick wrote: >> >> I disagree. When I develop web pages (using Django or otherwise) I use >> the Firefox HTML validator extension. This helps me write >> standards-compliant HTML -- a big red cross indicates a problem in my >> page. It is annoying if that big red cross no longer indicates anything >> (there might be problems *I* caused, or it might just be Django stuff). > >You realise that you're effectively confirming what I said, right?. The >big red cross is a cosmetic issue. The fact that it makes precisely zero >difference to the practical matter of how a real-world web browser >processes the page means it's not fatal/tragic. No, I think you may have misunderstood me. The XHTML slash is cosmetic; to my knowledge, all current browsers are capable of dealing with that (thus deviating from what the standard dictates them to do, but practicality beats purity, I guess ;)). However, *my* HTML (as opposed to Django's generated HTML) may contain errors as well, and regularly does. The big red cross in an invaluable indicator that I messed something up, and losing that functionality is annoying. Now, when using HTML as opposed to XHTML, I can no longer see if I did something wrong, as the page is *always* in error (from a standards compliance POV). >Then you'll have no trouble creating a parallel set of form widgets or a >form framework that can handle this and everybody will be happy. :-) No, I have no desire to do such a thing. As I stated before, the practical solution for me was to switch to XHTML. >Or look at the django-html project on Google Code, where various ideas >are being tried out. I did, briefly, and didn't like what I saw. They overcomplicate things, IMHO. I don't want DOCTYPE management, for example. >(you're certainly paid just as much to work on Django as me, for >example). This payment thing comes up regularly here, and pollutes the discussion. I have been using Django for a while, and found it to have good things and downsides (both IMHO). I have not even critisized Django here (yet ;)), just expressed mild curiousity. I don't think I've given you reason to bring up that you're not payed for your work on Django. >Maintaining two copies of everything certainly adds to the workload. I have not suggested such thing though. From a brief look at the source code, it appeared to me that it would be easy to create a setting that specifies whether to include the slash or not, and based on that setting write either " />" or ">" at the end of input tags (and ). However, like I said, I have not researched this thouroughly, and I most certainly have not requested the Django developers to implement this. I may have overlooked more complicated things, and besides, if I wanted this badly I'd try and write it myself and if successfull, attempt to get it included in Django. Regards, Gertjan. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: absolute_import, app names, dots, and a bug
On Wed, Jan 28, 2009 at 11:49 PM, Malcolm Tredinnickwrote: > > On Wed, 2009-01-28 at 22:50 -0500, Karen Tracey wrote: >> >> No, I don't think that's an accurate representation of the status. >> The triage state is Accepted and furthermore Malcolm even assigned it >> to himself, meaning he's intending to fix it. Per this comment: >> >> http://code.djangoproject.com/ticket/8193#comment:20 >> >> working on the fix has revealed other problems so it is not as simple >> as one might hope. So it's in the queue to be fixed, probably (I'm >> just guessing) prioritized behind some 1.1 feature work. > > That's correct. Also, this particular thread has provided the first > example of standard behaviour causing a problem, which is something > that's been requested a few times in that ticket and related threads. > > It will be fixed for 1.1. Since we now have a case of normal Python > usage triggering a problem, it will also be back-ported to the 1.0 > branch. All in good time. > > For now, not using "from __future__ ..." is an acceptable workaround. > Live in the present, not the future for a little while. :-) I misspoke. I should have said, "...people think it's a bug without consequences." I also realize my message could have been read in a demanding, annoyed way rather than in the teasing, needling way in which I meant it. I'm okay with living in the present. Especially since I've had four whole days to work on Django stuff since my school district (I teach CS at the high school level.) is closed all week because of an ice storm that has knocked out power at about 1/3 of the schools. Todd P.S. One of my former students has made a few thousand dollars writing Django sites since he graduated last May. Best advertising for my advanced classes I've ever had. :-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Has anyone looked into writing an SSH backend for file uploads?
On Jan 29, 1:19 pm, Christian Joergensenwrote: > What if one of the machines was unresponsive at the time of the upload? One option would be to have all the files uploaded locally, but the handler would additionally copy to the other locations. The other would just to be to have some exception handling. File uploads aren't a site user task for us, so short periods of broken upload capabilities are tolerable. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Has anyone looked into writing an SSH backend for file uploads?
Andrew Ingram wrote: [...] > Ideally you'd be able to provide it with a tuple of machines to > connect to which would allow you to upload to all the machines at once > (but even if there's one that only allows you to upload to one machine > that would still be useful). What if one of the machines was unresponsive at the time of the upload? Regards, -- Christian Joergensen http://www.technobabble.dk --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin screen counts correctly but returns no records
Thanks Daniel, I'll take your advice. I'm surprised (i.e. don't understand why) this approach is problematic though. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Has anyone looked into writing an SSH backend for file uploads?
Hi All, At the moment our Django apps run on the same server that the static images are served from, we are looking to change this to improve redundancy. Has anyone created (or attempted to create) a new file backend that uses SSH? Ideally you'd be able to provide it with a tuple of machines to connect to which would allow you to upload to all the machines at once (but even if there's one that only allows you to upload to one machine that would still be useful). Regards, Andrew Ingram --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Admin screen counts correctly but returns no records
On Jan 29, 12:00 pm, JonUKwrote: > I'm creating a new admin UI for User, separate to the standard admin > User interface - I have the following setup: > > class WebsiteUser( User ): > class Meta: > db_table = 'auth_user' > > class WebsiteUserAdmin( admin.ModelAdmin ): > list_display = ( 'username', ) > > admin.site.register( WebsiteUser, WebsiteUserAdmin ) > > When I view this, the admin list page correctly summarises "1 website > user", however it has no rows. > > Any ideas? Ideas? Yes: don't do that. If you just want to override the admin for User, then unregister the admin class for that model and re-register your own. Subclassing like this is bound to lead to all sorts of issues. admin.site.unregister(User) admin.site.register(User, MyCustomUserAdmin) Or if you really want to duplicate the user admin while leaving the original one intact, look into setting up multiple Admin sites: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adminsite-objects -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Admin screen counts correctly but returns no records
I'm creating a new admin UI for User, separate to the standard admin User interface - I have the following setup: class WebsiteUser( User ): class Meta: db_table = 'auth_user' class WebsiteUserAdmin( admin.ModelAdmin ): list_display = ( 'username', ) admin.site.register( WebsiteUser, WebsiteUserAdmin ) When I view this, the admin list page correctly summarises "1 website user", however it has no rows. Any ideas? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
#7210 - F() Query Expressions
Hi all, With [9792], I've committed F() query expressions to trunk. For details, see the docs: http://docs.djangoproject.com/en/dev/topics/db/queries/#filters-can-reference-fields-on-the-model There are two caveats worth knowing about: 1) This patch reveals a bug in the SQLite package that ships with Ubuntu Intrepid Ibex (SQLite 3.5.9-3). Versions of SQLite 3.5.9 on other operating systems (including Debian) don't appear to be affected, and other versions of SQLite on Ubuntu don't appear to be affected either. 2) F() expressions have not been updated to work with GIS fields. However, based on some initial discussions with Justin, it should be possible to make these changes without affecting any public API. If anyone with access and experience with contrib.GIS cares to help out on this front, assistance would be gratefully accepted; otherwise, we'll just have to wait until Justin surfaces from his Bar exams. Finally, some thank yous: Sebastian Noack for getting the ball rolling. Sebastian raised the original ticket and wrote the original patch. Not much of that patch survived into the final implementation, but his contribution is very much appreciated. Unfortunately, I forgot about Sebastian's original involvement when I wrote the commit message - for that, I apologize. Nicolas Lara for doing the heavy lifting as part of the 2008 Google Summer of Code. F() expressions were an optional item in his GSoC proposal, but he made such good progress on aggregates that we got two-for-one. Nicolas, take a bow - you did some excellent work here. Alex Gaynor provided some excellent assistance debugging and fixing a number of problems as we neared completion of the project (including narrowing down the mutant SQLite problem). Thanks Alex. Malcolm Tredinnick did his usual stunning job at reviewing code and picking holes in designs. Thanks Malcolm. Thanks also to the many people that contributed ideas during the design phase, and to those who tested the code as it was developing. Your efforts may not have ended up in the final design or turned into a bug report, but thanks for taking the time to look at an experimental feature. Yours, Russ Magee %-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: @cache_control() and @never_cache not working
In that version (0.96) of Django was bug in combination of these decorators and CacheMiddleware. If you can use upstream version then everything will be working. Otherwise look for these (closed) tickets on http://code.djangoproject.com and patch your version. Tomas Kopecek --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: 'FtrToolTags' is not a valid tag library: Could not load template library from django.templatetags.FtrToolTags, cannot import name Product
Well, i figured it out. As i said before, i upgraded from django 0.97 (svn) to 1.0.2 stable, BUT i didn't rebooted my server. So, when i looked at META INFORMATION in my browser, i saw that 0.97 version still being used, instead of the new version. I rebooted it and everything is normal again. =) pretty weird, ham ?! Thanks all Thiago. On Jan 29, 8:23 am, "Thiago F. Crepaldi"wrote: > Hello, > > in my templates pages, i do: {% load FtrToolTags %} > > in my FtrToolTags, i do: from webTool.ftrTool.models import Product > > i also use Product model on admin.py, forms.py, views.py and models.py > > Thanks, > Thiago > > On Jan 28, 11:21 pm, Malcolm Tredinnick > wrote: > > > On Wed, 2009-01-28 at 16:15 -0800, Thiago F. Crepaldi wrote: > > > in models.py all the code is ok. > > > What other files are using the Product model? In particular, how do you > > import it into the module(s) that are using it in template tags. > > Something in your code is not importing Product or importing it > > incorrectly. Find that place. > > > > Is there any procedure to "register" > > > Product ? > > > No. It only has to be imported. > > > Regards, > > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Search in a ManyToManyField in Admin interface
On Wed, Jan 28, 2009 at 7:36 PM, Ianwrote: > Yes, that's the problem. The admin automatically adds .distinct() to the > queryset whenever one of the search fields is in a related model, which > would trigger the error. Ok, got it. > This is a limitation of Oracle, and there's not a whole lot we can do > about it, other than to suggest you not structure your models that way. But in my case, it gotta have a TextField. > Probably your best solution will be to put the TextField in a separate > one-to-one related model. I tried it, but it became awful. For instance, every time that I add a Book, not only there's a list of all other descriptions already added, but also I've to add it in a separated window. I'm more inclined to change to a mysql db. Thanks, Ian! -- João Olavo Baião de Vasconcelos Bacharel em Ciência da Computação Analista de Sistemas - Infraestrutura joaoolavo.wordpress.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: template: writing "\u20ac 20.000" fails
Well, I thought it didn't escape the input string. I was wrong. I tried `escape_js` again and now it works just fine. It probably did before, but I don't remember why I thought it didn't. Regards, Sander On 28 jan, 04:28, Malcolm Tredinnickwrote: > On Tue, 2009-01-27 at 00:37 -0800, SanPy wrote: > > Thanks a lot, Malcolm, > > > You got me on the right track, I just needed to escape the string, > > like this: > > > var prices=[{% for price in prices %}[{{ price.0 }}, '{{ price.1| > > escape }}']{% if not forloop.last %},{% endif %}{% endfor %}]; > > > I tried the `escapejs` filter. That didn't work. > > What does "didn't work" mean? It raised an error? Your computer caught > on fire? > > The "escapejs" filter isn't broken and works quite well. The "escape" > filter does HTML-aware escaping, not Javascript-aware escaping. They are > different, so using the "escape" (of "force_escape") filter for data > intended for Javascript will lead to incorrect results. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: 'FtrToolTags' is not a valid tag library: Could not load template library from django.templatetags.FtrToolTags, cannot import name Product
Hello, in my templates pages, i do: {% load FtrToolTags %} in my FtrToolTags, i do: from webTool.ftrTool.models import Product i also use Product model on admin.py, forms.py, views.py and models.py Thanks, Thiago On Jan 28, 11:21 pm, Malcolm Tredinnickwrote: > On Wed, 2009-01-28 at 16:15 -0800, Thiago F. Crepaldi wrote: > > in models.py all the code is ok. > > What other files are using the Product model? In particular, how do you > import it into the module(s) that are using it in template tags. > Something in your code is not importing Product or importing it > incorrectly. Find that place. > > > Is there any procedure to "register" > > Product ? > > No. It only has to be imported. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to do Refbacks in Django?
Oh wait, you told me that too: MIDDLEWARE Okay, I'm all set, thanks so much. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: How to do Refbacks in Django?
Yes, thank you, but I already figured that out and made a stupid function add_to_log(request). What I am really wondering is, how do I avoid having to call add_to_log(request) in every single view function in views.py? Thanks. On Jan 28, 8:04 pm, Malcolm Tredinnickwrote: > You have access to all the HTTP headers in the request object that is > passed to your view. See [1] for details. Once you have that > information, recording it somewhere via a middleware or something should > be easy. > > [1]http://docs.djangoproject.com/en/dev/ref/request-response/#django.htt... > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: pb synchronize database to django
On Jan 29, 9:07 am, arbiwrote: > Hi, > > I am a newb in Django and I find it very nice... But the current > problem is that, when I try to synchronize my models (using python > manage.py syncdb), an attribute that I changed did not change in my > database. For instance : > > class Route (models.Model) : > name=. > attribute 2 > attribute 3 > etc. > > that I change to : > > class Route (models.Model) : > newNameAttribute=. > attribute 2 > attribute 3 > etc. > > Then I run python manage.py syncdb, everything goes well in the > shell, > EXCEPT : no changings in my database. > Then when I want to create an instance of Route I got a NameError :( > > Thanks for your help! Please read the lovely documentation, especially the bit in the big box here: http://docs.djangoproject.com/en/dev/ref/django-admin/#syncdb Then search the archives of this list for 'migrations'. -- DR. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
pb synchronize database to django
Hi, I am a newb in Django and I find it very nice... But the current problem is that, when I try to synchronize my models (using python manage.py syncdb), an attribute that I changed did not change in my database. For instance : class Route (models.Model) : name=. attribute 2 attribute 3 etc. that I change to : class Route (models.Model) : newNameAttribute=. attribute 2 attribute 3 etc. Then I run python manage.py syncdb, everything goes well in the shell, EXCEPT : no changings in my database. Then when I want to create an instance of Route I got a NameError :( Thanks for your help! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: can i use models like that??
On 28 jan, 23:09, Mirat Can Bayrakwrote: > Can you look at these, can they work? > > i tried that one but not worked, is there way to make it working? (nope, > there was no error messages, only strings are not shown at admin panel) > > LANGUAGE_OPTIONS = (('en_GB', '(British) English'), ('tr', 'Turkish'), ('es', > 'Spanish')) > class ShortDescription(models.Model): > strings = dict() > product = models.ForeignKey(Product) > for language in LANGUAGE_OPTIONS: > strings[language[0]] = models.CharField(max_length=300) Nope, this won't work - not that way at least. And I won't tell you how this _could_ be made to work, because AFAICT, it's a a very wrong design anyway. If what you want is to have per-language description of a same product, better do it the right way (wrt/ the relational model), that is using one record per product/language, ie: LANGUAGE_OPTIONS = (('en_GB', '(British) English'), ('tr', 'Turkish'), ('es', 'Spanish')) class ShortDescription(models.Model): product = models.ForeignKey(Product) language = models.CharField(choices=LANGUAGE_OPTIONS, max_length=4) text = models.TextField() My 2 cents... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Creating test databases. Nose framework
> > Generally, you'll want to wait more than 6 hours before asking again. A > couple of days, at least, would be a reasonable period. > Sorry...Will note On Thu, Jan 29, 2009 at 2:54 AM, Malcolm Tredinnick < malc...@pointy-stick.com> wrote: > > On Wed, 2009-01-28 at 17:19 +0200, Oleg Oltar wrote: > > Any idea? > > Generally, you'll want to wait more than 6 hours before asking again. A > couple of days, at least, would be a reasonable period. > > > On Wed, Jan 28, 2009 at 11:41 AM, Oleg Oltar> > wrote: > > Can't find how to add predefined data to the db. Sorry for > > being silly, maybe someone can point me? > > Add it just like you normally add objects to the database. Create them > in the test setup methods and save them. Or load them up with raw SQL. > > Regards, > Malcolm > > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---