Skip to content

Instantly share code, notes, and snippets.

@flavianmissi
Created October 10, 2011 12:37
Show Gist options
  • Select an option

  • Save flavianmissi/1275204 to your computer and use it in GitHub Desktop.

Select an option

Save flavianmissi/1275204 to your computer and use it in GitHub Desktop.
Django UpdateView sample
#views.py
from django.views.generic import UpdateView
class UpdateBook(UpdateView):
model = Book
form_class = BookForm
template_name = 'create_form.html'
success_url = '/books/'
#urls.py
from django.conf.urls import *
from library.views import UpdateBook
urlpatterns = patterns('',
url('^update_book/(?P<pk>[\w-]+)$', UpdateBook.as_view(), name='update_book'),
)
# you MUST pass a pk or slug param to this view
@zhwei

zhwei commented Feb 23, 2013

Copy link
Copy Markdown

thanks for your sharing, it's very helpful for me

ghost commented Mar 18, 2013

Copy link
Copy Markdown

Thank you flaviamissi, you saved me a lot of time.

@mayuroks

mayuroks commented Oct 7, 2013

Copy link
Copy Markdown

If u wanna call this from some template, the template should have an url like this
{% for book in object_list %}
<a href="{% url "update_book" book.pk %}"> UPDATE {{ book.name }}

This will display a list of books ...and update options besides it

@cgoodale

cgoodale commented Jun 9, 2014

Copy link
Copy Markdown

👍 Simple and to the point. Thanks

ghost commented Jun 14, 2016

Copy link
Copy Markdown

how to send context in success url?

@brunoferreira94

Copy link
Copy Markdown

Thank you! You are the best!

@alcidesrope

Copy link
Copy Markdown

Thank..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment