Re: dynamic choices in a ChoiceField

2008-01-13 Thread James Bennett
2008/1/13 Alex Koshelev <[EMAIL PROTECTED]>: > When you explicitly write list in choices it evaluates at module > import type. To avoid this write function and pass it as 'choices' > parameter Or... deck = forms.ModelChoiceField(queryset=Deck.objects.all()) -- "Bureaucrat Conrad, you are tec

Re: dynamic choices in a ChoiceField

2008-01-13 Thread Alex Koshelev
Thanks. My mistake On 13 янв, 21:39, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Alex Koshelev wrote: > > When you explicitly write list in choices it evaluates at module > > import type. To avoid this write function and pass it as 'choices' > > parameter > > > def get_choices(): > > [(d.id,d.

Re: dynamic choices in a ChoiceField

2008-01-13 Thread Fredrik Lundh
Alex Koshelev wrote: > When you explicitly write list in choices it evaluates at module > import type. To avoid this write function and pass it as 'choices' > parameter > > def get_choices(): > [(d.id,d.name) for d in Deck.objects.all()] (adding a return statement might be a good idea /F)

Re: dynamic choices in a ChoiceField

2008-01-13 Thread Alex Koshelev
When you explicitly write list in choices it evaluates at module import type. To avoid this write function and pass it as 'choices' parameter def get_choices(): [(d.id,d.name) for d in Deck.objects.all()] #... deck = forms.ChoiceField(required=True,choices = get_choices ) When this function

dynamic choices in a ChoiceField

2008-01-13 Thread Julian
Hi there, I have cards and decks, decks have ManyToMany cards, and if you want to add a card, you have to chose a deck; quite simple. my forms.py contains something like that: class CardForm(forms.Form): deck = forms.ChoiceField(required=True,choices=[(d.id,d.name) for d in Deck.objects.all