On Tue, Feb 10, 2009 at 3:24 PM, wynfred <stephenlapoi...@gmail.com> wrote:
> > I'm sure there is a simple solution here, but I've been searching the > forum archive and elsewhere but so far haven't found an answer. > > I have a form that uses some dynamic ModelChoiceField fields, > filtering the model for the logged-in user. > > The form in app's forms.py, slightly abridged, is like this: > > class SystemAlertForm(forms.ModelForm): > usermessaging = forms.ModelChoiceField(label='Messaging address', > queryset=UserMessaging.objects.filter(isactive=True)) > def __init__( self, user, *args, **kwargs ): > super( SystemAlertForm, self ).__init__( *args, **kwargs ) > self.fields['usermessaging'].queryset = > UserMessaging.objects.filter(isactive=True,user=user) > > Then in the view, after a POST, I have a line of code like this: > > form = SystemAlertForm(request.POST, user=request.user, > instance=alert) > > But there is an error: __init__() got multiple values for keyword > argument 'user' > > When displaying a bound form for a user, the form is fine: it displays > this usermessaging ModelChoiceField correctly filtered -- and I call > it the same way but without the request.POST: > form = SystemAlertForm(user=request.user, instance=alert) > > But, after a POST, it displays the error above. > > Thanks in advance for any guidance. > > > > The issue is you are passing the kwarg "user" after the arg. Since user is the first param when you pass request.POST as the first arg it assumes it is user. Reorganize your arguments in some(make user first, or pass request.POST as a kwarg) way. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---