I used a similar technique as well. Instead of adding another parameter , I used "initial=" parameters in view which is passed through **kwargs. form = NewCaseForm(initial={'my_group': data}). and my solution seems more hack than yours. But it works too. Passing through *args, bind the form and trigger the validation, so that does not work.
Wish Django had better documentation. Looks like they are waiting for 1.0 to write more docs so that they do not have redo docs and the best practices. I guess I will write a e-book when I am done with my App as my token of appreciation for Django team and the support on the online forum. The django book is good but really does not add much to the online docs. Ashish On Apr 10, 9:15 am, Dan <[EMAIL PROTECTED]> wrote: > ok I seem to have been able to make it work by passing in an extra > parameter in through the __init__ is this the best solution?? even > though it works it feels like i am doing something incorrect... > > class AddMemberForm(forms.ModelForm): > def __init__(self, obj, *args, **kwargs): > super(AddMemberForm, self).__init__(*args, **kwargs) > self.fields['member'].queryset = > Member.objects.filter(userprofile=obj) > > class Meta: > model = ProductMember > exclude = ('product') > > On Apr 11, 12:29 am, Dan <[EMAIL PROTECTED]> wrote: > > > Hi > > > I am trying to create a ModelForm with a ModelChoiceField which has a > > should have a limited queryset that is filtered by the userprofile > > logged in, so far i have this: > > > class AddMemberForm(forms.ModelForm): > > member = > > forms.ModelChoiceField(Member.objects.filter(userprofile=userprofile)) > > class Meta: > > model = ProductMember > > exclude = ('product') > > > How do I go about getting the 'userprofile' varible in to this class? > > Or is there some better other way to do this? > > > Thanks in advance > > > Dan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---