You can pass the competition instance to the for in the initialization. In the form you change the form a little bit adding the init method to receive the competition parameter. Then you can save it in a form attribute and then use it in clean method.
I made a simple gist to show you haw it could be: http://gist.github.com/358245 I always recomend not to get values from cleaned_data directly (self.cleaned_data['dob']) becouse 'dob' may be invalid before the clean is called so it will raise an IndexError. I prefer to use self.cleaned_data.get('bob') to avoid it. ______________________ VinÃcius Mendes Solucione Sistemas http://solucione.info/ On Tue, Apr 6, 2010 at 6:32 PM, When ideas fail <andrewkenyon...@gmail.com>wrote: > hello, i have a clean method in my forms.py. I want this to check a > person is old enough to enter a competiton > > The problem i have is that the minimum age changes and is a field in > the competition model(it is entered by the user). > > My clean method is like this (pseudo code): > > class personform(forms.Form): > ................... > > def clean_recipients(self): > dateOfBirth = self.cleaned_data['dob'] > if dateOfBirth > competition.min_age > ...... > return data > > The same form is used to enter any competition, and uses the url to > get the competition id > > eg: mysite.com/enter_competition/my_competition > > since competition_slug will only become apparent from the url in views > how can i find out the relevant min_age for my clean method in > forms.py? > > I would be greatful for any help, sorry if i haven't explained this > very well. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.