Re: Dynamic queryset to ModelChoiceField
Or `Topic.objects.none()` On Apr 15, 8:46 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Sure, just give the modelchoicefield Topic.objects.all() to start > with, as this will never actually get used. > > On Apr 14, 11:14 pm, shabda <[EMAIL PROTECTED]> wrote: > > > I have a form where I want to do something like, > > > class SetDefaultForm(forms.Form): > > topics = forms.ModelChoiceField() > > > def __init__(self, user): > > super(SetDefaultForm, self).__init__() > > self.fields['topics'].queryset = Topic.objects.filter(user) > > > This does not work, of course, as ModelChoiceField has queryset as > > required argument. > > > So I have to do something like, > > > class SetDefaultForm(forms.Form): > > topics = forms.ChoiceField() > > > def __init__(self, user): > > super(SetDefaultForm, self).__init__() > > self.fields['topics'].choices= [topic for topic in > > Topic.objects.filter(user)] > > > Is there a better way? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Dynamic queryset to ModelChoiceField
Sure, just give the modelchoicefield Topic.objects.all() to start with, as this will never actually get used. On Apr 14, 11:14 pm, shabda <[EMAIL PROTECTED]> wrote: > I have a form where I want to do something like, > > class SetDefaultForm(forms.Form): > topics = forms.ModelChoiceField() > > def __init__(self, user): > super(SetDefaultForm, self).__init__() > self.fields['topics'].queryset = Topic.objects.filter(user) > > This does not work, of course, as ModelChoiceField has queryset as > required argument. > > So I have to do something like, > > class SetDefaultForm(forms.Form): > topics = forms.ChoiceField() > > def __init__(self, user): > super(SetDefaultForm, self).__init__() > self.fields['topics'].choices= [topic for topic in > Topic.objects.filter(user)] > > Is there a better way? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Dynamic queryset to ModelChoiceField
I have a form where I want to do something like, class SetDefaultForm(forms.Form): topics = forms.ModelChoiceField() def __init__(self, user): super(SetDefaultForm, self).__init__() self.fields['topics'].queryset = Topic.objects.filter(user) This does not work, of course, as ModelChoiceField has queryset as required argument. So I have to do something like, class SetDefaultForm(forms.Form): topics = forms.ChoiceField() def __init__(self, user): super(SetDefaultForm, self).__init__() self.fields['topics'].choices= [topic for topic in Topic.objects.filter(user)] Is there a better way? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---