date - Django question: Having a problem with saving -


hello have edit item form. view, @ item.current_item_status_date.

def edit_item(request, client_id = 0, item_id = 0):     client = none     item = none     status = none     contact = none     status_id = request.post.get('status_id', none)     contact_id = request.post.get('contact_id', none)     save_item = request.post.get('save_item', none)     save_status = request.post.get('save_status', none)      try:         client = models.client.objects.get(pk = client_id)         item = models.storageitem.objects.get(pk = item_id)     except:         return httpresponsenotfound()     try:         status = models.status.objects.get(pk = status_id)         contact = models.contact.objects.get(pk = contact_id)     except:         pass     if request.method == 'post':         form = forms.itemform(request.post, instance = item)         if form.is_valid() , save_item not none:             item.current_item_status_date = date.today()             item.save()             form.save(true)             request.user.message_set.create(message = "item {0} has been updated successfully.".format(item.tiptop_id))             return httpresponse("<script language=\"javascript\" type=\"text/javascript\">window.opener.location = window.opener.location; window.close();</script>")          if status not none , contact not none , save_status not none:             current_status = models.itemstatushistory(item = item, contact = contact, status = status,                                                     user = request.user)             current_status.save()             request.user.message_set.create(message = "item status has been updated successfully.")     else:         form = forms.itemform(instance = item)     title = str(client) + ' : edit item'     status_list = models.status.objects.all()     return render_to_response('edit_item.html', {'form':form, 'title':title, 'status_list':status_list, 'item':item}, context_instance = requestcontext(request)) 

current_item_status_date saves todays date when form submitted. however, there small problem. in form, want save when button called new status selected. right edit item form doing it's saving when save button selected. want form save date when new status selected - not save.

here have in edit order template.

<td><input type="submit" name="save_status" value="new status"></td> <input type="submit" name="save_item" value="save" onclick="validate_item(this.form)"> 

edit:: have done these changes.

#code  if request.method == 'post':     form = forms.itemform(request.post, instance = item)     if form.is_valid() , save_item not none:         form.save(true)         request.user.message_set.create(message = "item {0} has been updated successfully.".format(item.tiptop_id))         return httpresponse("<script language=\"javascript\" type=\"text/javascript\">window.opener.location = window.opener.location; window.close();</script>")     if request.post.get('save_status'):         item.current_item_status_date = date.today()         item.save() #code 

now, doing this, current item status date saved. if close form (it form opens new window). not saved when select status date , click save. think not getting saved the current_item_status_date field, rather database. can tell not working when click on save status, field current_item_status not update. updates when close form , open again. way work if form reloads getting information database.

this looking for:

  • clicking on status date should save date.
  • clicking on status date , clicking on save should save date.
  • just clicking on save should not save status date.

you checking save_item. change save_status , should fine if understand question.

 if form.is_valid() , save_status not none: 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -