Hi Jonas,

I had a similar problem (wanted to restrict queryset of
a(ModelMultipleChoiceField by user), this is what i did :

In the init method of the form pass user as the argument and in the
views.py file when instantiating the form pass the param
user=request.user

see below for about how to restrict options of a ManytoMany field
based on the logged in User

class AddInterviewForm(forms.Form):
    def __init__(self, user, *args, **kwargs):
        super(AddInterviewForm, self).__init__(*args, **kwargs)
        self.fields['interviewers'] =
forms.ModelMultipleChoiceField(queryset=Interviewer.objects.filter(cmpny_id=user),required=True)

    candidate        = forms.CharField(label=u'Candidate name',
max_length=100)
    candidate_email = forms.EmailField(label=u'Candidate Email')
    candidate_tel   = forms.CharField(label=u'Candidate Tel',
max_length=15)
    scheduled_time  =
forms.SplitDateTimeField(widget=SplitDateTimeWidget)


Lemme know if the above works for you

Thanks,
KP

On Jul 23, 1:16 am, Jonas Geiregat <jo...@geiregat.org> wrote:
> Hello,
>
> How would I limit the results of a foreign key of a queryset ?
> Ie. I have the models Person and Task. I want to get all Person's but only 
> get their 2 latest tasks.
>
> Person__task points to Task__name
> It's a ManyToMany Relationship.
>
> Jonas Geiregat
> jo...@geiregat.org

-- 
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