Tuesday, August 2, 2011

using the request object inside a form

Hello there.

I need to use parts of the URL to calculate some thing inside my form.

Here's a stripped down version, I can't seem to get it to give me
anything other than none for self.request :-(

class EventBookForm(ModelForm):
title = CharField()
firstname = CharField()
surname = CharField()
address = CharField(widget=Textarea(attrs={'rows': 5, 'cols': 80}))
postcode = CharField()
telephone = CharField()
email = EmailField()
workshops = MultipleChoiceField()
requirements = CharField(widget=Textarea(attrs={'rows': 5, 'cols':
80}))

class Meta:
model = Event

def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
print self.request
super(EventBookForm, self).__init__(*args, **kwargs)
workshop_choices = []
data = Workshop.objects.filter("some rules based on what I get back
from the request object, which is currently none")
for d in data:
workshop_choices.append((d.title,d.title))

self.fields['workshops']=MultipleChoiceField(widget=CheckboxSelectMultiple,
choices=workshop_choices, required=False)

I'm pretty certain I'm doing something unbelievably stupid but I am
trying, honestly!

Anyone got any ideas?

--
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