today in the project encountered a problem, there is a Django additions and deletions to the template page, where the editing page uses a custom form to build the display content. The data of the form is queried from the database, and when the contents of the database are modified, the information displayed by the form is not modified. When the restart is completed, the data of the form is reloaded. a lot of data, no answer to the load time of form form data.
From the point of view, when the data of a form is loaded, it is loaded when the service starts. The code is as follows:
view.py
def testform (req): Form = Testforms.testform () print ' >>> ', form return Render_to_response ("test.html", {' Form ': Form})
urls.py
#form测试 URL (r ' ^test/form/$ ', ' manager.makoViews.testform '),
models.py
From Django Import forms Import Models Class Testform (forms. Form): Device_types = models. Role.objects.all (). Values_list (' id ', ' name ') name = forms. Charfield (Widget=forms.widgets.select (choices=device_types))
Html
<! DOCTYPE html>
Problem solving:
I met a buddy in the Django group today. Question How to write the select value in the form, I give an answer.
Name = forms. Charfield (Widget=forms.widgets.select (choices=device_types))
Then he said it could not update the value in time and continue to ask for advice. Get
Name2= forms. Modelchoicefield (label=u ' name2 ', queryset=models. Role.objects.all (), to_field_name= "id")
instantly solved my big problem, thanks again to that Buddy.
By default, the option value of the select that is generated in the page is Queryset key, and the value is the value returned by the __unicode__ method in the Queryset model.
--- 2015-06-19 13:41 Records
---levels are limited and personal records are for reference only.
Data loading issues for Django form forms