Tuesday, May 31, 2011

Accessing request.user in formset validation

Hi all,

in some of my forms and formsets I need access to request.user in form

With an individual form, I pass request.user as a parameter to the
constructor, using code like this:

class ErfasseZeitraumForm(forms.Form):
von = forms.DateField(widget=AdminDateWidget())
bis = forms.DateField(widget=AdminDateWidget())

def __init__(self, User, *args, **kwargs):
super(ErfasseZeitraumForm, self).__init__(*args, **kwargs)
self.User = User

How can I achieve the same for entire formsets?

I'm still quite new to Python, and I'm unsure what to override where to
make the formset factory pass the request.user to all form constructors,
or even if that is the "best" and canonical way to this?

Thank you very much!

Best regards,

Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
Learn more at http://www.cafu.de

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.

No comments:

Post a Comment