On Jun 19, 4:36 pm, Adi <[EMAIL PROTECTED]> wrote:
> In order to set up the initial values on a couple of fields of my
> form, I need to pass in a couple of model objects to my ModelForm's
> init method.

Try this::

    class YourForm(forms.ModelForm):
        class Meta:
            ...

        def __init__(self, *args, **kwargs):
            # pop() your custom keyword args before calling super()
            self.modelobj1 = kwargs.pop('modelobj1', None)
            self.modelobj2 = kwargs.pop('modelobj2', None)
            super(YourForm, self).__init__(*args, **kwargs)

    # Call like this:
    modelobj1 = SomeModel.objects.get(id=1)
    modelobj2 = SomeModel.objects.get(id=2)
    form = YourForm(modelobj1=modelobj1, modelobj2=modelobj2)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to