python - Open / Edit / Save record in Django Form -


Currently I have a Django form where I can add a new customer to the database. I currently have a table showing all the customers present in this database. Now I would like to click on the customer's name in the Customer table so that the existing customer can open and have the option to edit and save the record.

Below are my current code sections, if more important, please ask.

My navbar.html

  & lt; Li & gt; & Lt; A href = '%} "with customer'%} 'customer with {% url} New customer & lt; / A & gt; & Lt; / li & gt;   

my urls.py

  url (r '^ customeradd / $', 'customer.views.customeradd', name = 'customeradd'),   

My views.py

  def customer application (request): form = CustomerAddForm (request.POST or none) if request.method == 'POST ': If form.is_valid (): save_it = form.save (commit = false) save_it.save () messages.success (request,' customer has successfully added ') HttpResponseRirectirect (' / customeroverview / ') Other: messages Error () request, 'customer save error, please check the field below') Other: form = CustomerAddForm () return to render_to_response ("customer-add.html", {"customer_add_form": form}, context_instance = RequestContext (request))   

customeroverview.html which shows the table of all customers (only three fields are shown)

  & lt; Td> & Lt; A href = '{% url' customeradd "%} '& gt; {{customer.customer_name}} & lt; / a & gt; & lt; / td & gt; & lt; td & gt; {{customer. Customer_type}}  & lt; td & gt; {{customer.customer_address}} & lt; / td>   

So now I'm in the Customer Table Customers can click on the name of the customer and the customer will open the adform. In the current situation, the offers are not empty because no argument is given.

  1. customer.viewer.html at customer How do I give the customer.id field as argument when clicking on the customer_name hyperlink?

  2. I will give this c How to see the ID. - How should urls.py look like?

  3. When the form is opened with an existing customer, how do I create a new customer? I save the existing record instead. ID

    Any help / suggestion on this situation would be very useful in my understanding of Django GET / POST.

    Maybe you should:

    urls.py url (r '^ Customeradd / (' P & LT; ID & gt; \ W +) $ ',' customer.views.customeradd ', name =' customeredit '), url (r' ^ customeradd / $ ',' customer.views.customeradd ', name =' customer adid '),

    In your view.py: def customeradd (request, id = none): If ID: Customer = Customer.Bejects (Pk = id) other customer = no form = customer application (request.post, example = customer) .....

    in your template

    & lt; Td> & Lt; A href = '{url url}' Customer customer.ID%} '& gt; {{Customer.customer_name}} & lt; / A & gt; & Lt; / Td> & Lt; Td> {{Customer.customer_type}} & lt; / Td> & Lt; Td> {{Customer.customer_address}} & lt; / Td>

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -