Michael Ackerman
unread,May 13, 2012, 5:59:50 AM5/13/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
My updateview seems to be creating another object instead of updating the object. The good news is my UpdateView form is filled in with initial data, but when I press submit, it creates a new ticket instead of updating the old one.
#views.py
class create_ticket(CreateView):
model = ticket
form_class = ticket_form
template_name = "create_ticket.html"
success_url = "/tickets/thanks/"
class update_ticket(UpdateView):
model = ticket
form_class = ticket_form
template_name = "create_ticket.html"
success_url = "/tickets/thanks/"
#models.py
class ticket(models.Model):
title = models.CharField(max_length = 100)
date_created = models.DateTimeField(auto_now_add=True)
description = models.TextField()
ranking = models.PositiveIntegerField(default=0)
def __unicode__(self):
return self.title
#urls.py
urlpatterns = patterns('',
(r'^$',
ticket_list.as_view()),
(r'^(?P<pk>\d+)/$',
ticket_detail.as_view()),
(r'^create/$',
create_ticket.as_view()),
(r'^thanks/$',
thanks_view.as_view()),
(r'^(?P<pk>\d+)/update/$',
update_ticket.as_view()),
)
My other 2 quick questions:
- Is the success_url and redirecting necessary?
- Is it possible to combine the create_ticket view and the update_ticket view?
All help is greatly appreciated.