Django's backstage function is very powerful, I first write a little bit (I novice).
1, first create the database (I use the python2.7):
The characters displayed in the field are for easy background management
class Thequestion (models. Model):
Name=models. Charfield (U ' questionnaire name ', max_length=30)
Number=models. Integerfield (U ' questionnaire filled in number ', default=0)
Create_time=models. Datetimefield (auto_now_add=true)
def __unicode__ (self):
return self.name
class questionproble M (models. Model):
Questions=models. ForeignKey (thequestion)
Problem_name=models. Charfield (the name of the U ' title ', max_length=200)
Ques_type=models. Booleanfield (Type of U ' problem ', default=false) #为False时为单选题
def __unicode__ (self):
return self.problem_name< br>
Class Choice (models. Model):
Question=models. ForeignKey (Questionproblem)
Choice_text=models. Charfield (U ' option name ', max_length=200)
Votes=models. Integerfield (Number of U ' selections ', default=0)
def __unicode__ (self):
return self.choice_text
2, operation in admin.py, temporarily do not know how to integrate the questionnaire name + title + options on the same page
Class Questioninline (admin. Tabularinline): #为了在问卷页面输入你的问卷题目这是默认有6题
Model = Questionproblem
Extra = 6
Class Choiceinline (admin. Tabularinline): 4 options per question
Model = Choice
Extra = 4
Class Questiionadmin (admin. Modeladmin):
FieldSets = [
(None, {' Fields ': [' Problem_name ']}), #在后台可以看到问题名称
(None, {' Fields ': [' Ques_type ']}), #题的类型
]
Inlines = [Choiceinline] #题对应的选项
Class Theadmin (admin. Modeladmin):
FieldSets = [
(None, {' Fields ': [' name ']}), # The name of the questionnaire
(None, {' Fields ': [' number ']}), #问卷答题数量
]
Inlines = [Questioninline] #问卷对应的题
Admin.site.register (Questionproblem, Questiionadmin)
Admin.site.register (Thequestion, Theadmin)
Admin.site.register (Choice)
Django Admin Background Operations database take a survey as an example