On Mar 6, 10:37 am, gregor kling <gregor.kl...@dvz.fh-giessen.de> wrote: > Hello List, > > I have a form inheriting from ModelForm. > class C(ModelForm): > <overidden field definitions> > > class Meta: > model = SomeModel > > def clean_somefield: > enhanced checks > > Now my problem is how to access session data (request.session) > from within the clean method. > Does anyone have a clue how to this. > > gfk
Override the form's __init__ method to accept the request as a keyword parameter, and stash it in an instance attribute. class MyForm(forms.ModelForm): def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') super(MyForm, self).__init__(*args, **kwargs) def clean_somefield(self): .. do something with self.request... form = MyForm(request.POST, request=request, instance=myinstance) -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---