On Fri, Aug 19, 2016 at 02:38:02PM +0200, Michal Petrucha wrote: > On Fri, Aug 19, 2016 at 05:02:39AM -0700, bobhaugen wrote: > > On Friday, August 19, 2016 at 5:20:45 AM UTC-5, Michal Petrucha wrote: > > These questions remain unanswered, although I intend to do a bunch more > > testing: > > > > 1. How pervasive is this problem? Does it affect template variables like > > {{ object.foreign_key_method }} where the foreign_key_method returns a > > queryset? > > 2. Is this behavior clearly documented anywhere? > > Honestly, I'm not sure what exactly you're asking here. Your > implementation of ``with_user`` was hard-wiring a queryset filter > based on the state of the database at the time ``with_user`` was > called. The rest is just standard Python behavior – since the method > was called during import (in the ModelForm definition), the result of > that call was used for the rest of the process' lifetime.
Actually, let me rephrase that. This problem you encountered here wasn't a case of “you need to set the ``queryset`` argument of ``ModelChoiceField`` in your form's ``__init__``,” but rather a case of “don't do too much filtering in your Python code – let your database do the filtering”. Using ``__init__`` to set the queryset is not really a very standard thing to do. It's just a workaround to make a form work if it uses a manager or queryset method that does not behave entirely correctly. Does this help make things at least a little bit clearer? Michal -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20160819131204.GK27882%40koniiiik.org. For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: Digital signature