Monday, June 20, 2011

Re: UpdateView help

To get keywords from your url, take a look at self.kwargs.

Remember you are working with a Class now, and keeping that in mind is
fundamental to not getting frustrated with the new CBVs.
get_object() is a method that can be overridden by subclasses. Browse
the source code for the CBVs to and try to understand what are some of
the methods defined by the superclasses.

That said, the documentation is indeed lacking. Unfortunately, my
knowledge of the API is rather limited, so I was hoping other
developers could contribute to it.

Sincerely,
Andre Versa

On 6/20/11, Tim Shaffer <timshaffer@me.com> wrote:
> Django automatically calls get_object() to get the object that needs to be
> updated by your form.
>
> There is a default get_object() method in the SingleObjectMixin that just
> gets the object based on the "model" and the "pk" that's passed in:
>
> https://code.djangoproject.com/browser/django/trunk/django/views/generic/detail.py#L19
>
> If you need different functionality, you can overwrite that method. But
> otherwise, there's no need. In your case, you could write it like this:
>
> def get_object(self):
> return Response.get(pk=self.kwargs.get('pk'))
>
> But since that's what the default get_object() already does, there's no need
> for you to specify either "object" or "get_object()"
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/IthGAEQnBMMJ.
> 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.
>
>

--
Sent from my mobile device

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