I have a modelform something like this: class EventContactForm(ModelForm): def __init__(self, *args, **kwargs): super(EventContactForm, self).__init__(*args, **kwargs) self.fields['event'].queryset = Event.objects.filter(category__slug= *SLUGFROMURLHERE* ).filter(active=True).filter(start_date__gt=datetime.date.today()) self.helper = FormHelper() self.helper.attrs = {'id': 'id-eventForm', 'class': 'form-vertical', 'autocomplete': 'off'} self.helper.html5_required = True self.helper.layout = Layout( 'event', 'first_name', 'last_name', 'company', 'telephone', 'email_address', 'message', Submit('submit', 'Submit', css_class='btn btn-primary'), )
I am having trouble accessing the slug from the url in order to perform the queryset filter (*SLUGFROMURLHERE*). I am trying to avoid having multiple forms for different category scenarios, because apart from the "event" field, the rest of the forms are identical. Many thanks for any help. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b0d51568-0f0a-40fa-a205-b910c4207b57%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.