Hi I'd like to use it in a forms.py to retrieve users own photos to attach to a blogpost. So actually this would do the job
def __init__(self, *args, **kwargs): self.user = kwargs.pop('user') super(forms.Form, self).__init__(*args, **kwargs) self.fields['url'].queryset = Image.objects.filter(member=self.user) But I run into a a keyerror because of the pop() function http://dpaste.com/146191/ Where can i find more information about the pop() function because it's not really clear to me. Found so far http://docs.python.org/tutorial/datastructures.html but it still remains unclear to me. This is the queryset which works in the view Image.objects.filter (member=request.user) Thanks guys On Jan 14, 8:38 pm, Tom Evans <tevans...@googlemail.com> wrote: > On Thu, Jan 14, 2010 at 6:39 PM, GoSantoni <mj.schuur...@gmail.com> wrote: > > Hi > > > Is it possible to use extra filter on a ModelChoiceField? > > > Tried several strategies: > > > if photo.member == user: > > url = forms.ModelChoiceField(queryset=Image.objects.filter()) > > > or > > url = forms.ModelChoiceField(queryset=Image.objects.filter > > (member__id=1)) > > > or > > > if Image.objects.filter(member__id=1): > > url = forms.ModelChoiceField(queryset=Image.objects.filter > > (member__id=1)) > > > All fail to filter on the member / user > > > Thanks > > The technique I use to do forms like this is to add the queryset in > the constructor, passing in whatever I need to filter it. > > Eg: > > class AttachmentForm(forms.Form): > name = forms.CharField(max_length=32) > url = forms.ModelChoiceField(queryset=Image.objects.none()) > def __init__(self, *args, **kwargs): > self.user = kwargs.pop('user') > super(forms.Form, self).__init__(*args, **kwargs) > self.fields['url'].queryset = Image.objects.filter(user=self.user) > > Cheers > > Tom
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.