Thursday, September 25, 2014

kwargs are not available in the get_context_method of generic CreateView, why?

Please help:

I am using Django's Class based Generic CreateView:

url:
http://127.0.0.1:8000/buchung/pilotkurs/2/

urls.py
urlpatterns = patterns("",
    url(r'^(?P<slug>[a-z0-9_-]{3,50})/(?P<offer_id>\d+)/$', OrderCreateView.as_view(), name='form'),
)

There are clearly kwargs, that I use. My context processor picks them up and they can be used in my template, but
in the view, there is only one kwarg, which is the form: My print statement below has the following output:

{'form': <django.forms.models.UserAccountForm object at 0x111725e50>}

.view.py:
class OrderCreateView(CreateView):

    template_name = 'order/order_register.html'
    model = UserAccount
    fields =('about',)

    def get_context_data(self, *args, **kwargs):
        print kwargs
        context = super(OrderCreateView, self).get_context_data(*args, **kwargs)
        courseevent = CourseEvent.objects.get(slug=kwargs['slug'])

How can I get related objects into my context with CreateView or what should I use instead. Any suggestions would be most welcome, 
since I somehow struggle to understand this.

      with kind regards and thanks in advance
           Sabine

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f4b1caee-87e8-4e83-8b4f-8bacaf9f7947%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment