Django UpdateView creates a new object instead of updating the current object -
everytime use updateview , try change attributes creates new object in database using new unique primary key. model below.
class delivery(models.model): created_date = models.datetimefield('date created', editable=false) modified_date = models.datetimefield('modified', editable=false) user_name = models.foreignkey(user, null=false) stream_name = models.charfield(max_length=50, null=false) view_name = models.charfield(max_length=100, null=false, blank=true) activity_name = models.charfield(max_length=100, null=false, blank=true) jira = models.urlfield() codereview = models.urlfield() related_streams = models.charfield(max_length = 100, choices=sorted(streams())) description = models.textfield(null=false,blank=true) status = models.booleanfield(default=false, blank=false) class meta: verbose_name = "delivery" verbose_name_plural = "deliveries" unique_together = (("user_name", "view_name", "activity_name"),)
for form using modelfactoryform updateview uses default pick out form_class using model itself.
class updateentryview(updateview): template_name = 'tracker/update.html' model = delivery success_url = reverse_lazy('table_view') status = streamstatus() fields = ['stream_name','view_name','activity_name','jira','related_streams','description','status'] def get_context_data(self, **kwargs): ctx = super(updateentryview, self).get_context_data(**kwargs) ctx['locked'] = self.status.getlocked() ctx['unlocked'] = self.status.getunlocked() return ctx
the html template below :
... {% block content %} <form action="/tracker/entry/" method="post" class="form"> {% csrf_token %} <div class="form-goup"> <div class="panel panel-default"> <div class="panel-heading">enter codereview link , let machine work ...</div> <div class="panel-body"> <div class="input-group"> <i class="glyphicon glyphicon-link input-group-addon" aria-hidden="true"></i> <input type="text" class="form-control" name="codereview" placeholder="codereview link"> </div> </div> </div> <hr> <div class="panel panel-default"> <div class="panel-heading">add entry manually ...</div> <div class="panel-body"> {% bootstrap_form form %} </div> </div> <hr> {% buttons %} <button type="submit" class="btn btn-primary btn-block"> {% bootstrap_icon "lock" %} submit </button> {% endbuttons %} </div> </form> {% endblock %} ...
is flaw in updateview or on part screwing up.
is possible url pointing createview instead of updateview?
Comments
Post a Comment