My hero - that worked for time!

Many many thanks.


On Jan 23, 12:37 pm, Alex Koshelev <daeva...@gmail.com> wrote:
> Your query executes in module import time and it happens only one time. So
> you cannot reevaluate it using choices field param like that.
>
> Solution - redefine form `__init__` and manually reassign choices to given
> field every time form is created.
>
> def __init__(self, *args, **kwargs):
>    super(MyForm, self).__init__(*args, **kwargs)
>    self.fields['carmake'].choices = Carmake.get_makelist()
>
> On Fri, Jan 23, 2009 at 3:20 PM, phoebebright 
> <phoebebright...@gmail.com>wrote:
>
>
>
> > Have been reluctant to post on this one as have come across many many
> > discussion during the 3 days of lack of success on resolving this
> > issue, but none has left me with a solution.
>
> > I have a form with a dropdown generated from a query.
>
> > This is in the form:
> >    carmake = forms.ChoiceField(choices=Carmake.get_makelist(),
> > label='Make')
>
> > This is in the model:
>
> > class Carmake(models.Model):
> >    name = models.CharField('Make', max_length=20)
>
> >    def __unicode__(self):
> >        return self.name
>
> >   �...@classmethod
> >    def get_makelist(a):
>
> >         return [('Any', 'Any Make')] + [(item, item) for item in
> > Car.objects.all().values_list('model__make__name',
> > flat=True).select_related().distinct()]
>
> > Predictably, the dropdown doesn't update when new makes are added
> > unless I restart the apache server.  I have tried everything suggested
> > by other posts and the example above is a close as I can get to the
> > example in the documentation that suggests these two queries will both
> > be evaluated.
> > >>> print [e.headline for e in Entry.objects.all()]
> > >>> print [e.pub_date for e in Entry.objects.all()]
>
> > I understand this has been discussed to death, but can someone please
> > enlighten me on a solution which will ALWAYS re-evaluate this 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to