Matt Davies wrote:
> Hello everyone
>
> I've got a views.py in my forms application that emails form data off to
> another department.
>
> It's a bookign form for events that appears on the events details page.
>
> www.bongo.com/events/EVENTSLUG
>
> The form is displayed in a template and is on our web site, works a treat.
>
> I've also got a forms.py in the application, in which we define the contents
> of the forms in classes.
>
> eg.
>
> class TrainingEventForm(Form):
> """A form for email bookings of training events"""
> firstname = CharField()
> surname = CharField()
> username = CharField()
>
> I need to be able to pull out the EVENTSLUG from the referring URL in the
> form in order to only select the event that has that slug.
>
> I know how to do it in a view with request.META, but I'm in a form now,
> there is no request and Form does not have an object type of META.
>
> Anyone got any ideas how to pull that data out of the reffering URL? Or
> even a better suggestion on how to accomplish this.
Shouldn't you just have an entry like this in your urls.py:
(r'^events/(?P<event_slug>[^/]+)', 'project.application.views.view')
And in your view collect the slug and look it up:
def view(request, slug):
s = get_object_or_404(Event, slug__exact=slug)
I don't understand why you are talking about forms here :)
--
Christian Joergensen | Linux, programming or web consultancy
http://www.razor.dk | Visit us at: http://www.gmta.info
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---