Friday, July 8, 2011

Re: User based objects

On Fri, Jul 8, 2011 at 10:28 AM, Praveen Krishna R
<rpraveenkrishna@gmail.com> wrote:
> Thank you, Shawn, I didn't knew that! I'm trying on that way now!
>

You're welcome. The one 'gotcha' is that you're going to have to
remove the user from the kwargs before you call the __init__ of the
superclass. Otherwise you'll get an 'unexpected keyword argument'
exception.

Example:


def __init__(self, *args, **kwargs):

self.user = kwargs.pop('user')

super(MyForm, self).__init__(*args, **kwargs)


You can then use self.user in your form's functions for filtering --
probably starting right in __init__ after the super() call to set
self.fields['field_name'].choices to be whatever they should be.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate