要求及文件
用户可以添加新主题,添加新条目,以及编辑既有条目
forms.py urls.py views.py html
new_topic.html new_entry.html
edit_entry.html
添加新主题
new_topic.html
topics.html
添加新条目
new_entry.html
topic.html
编辑条目
edit_entry.html
topic.html
代码
forms.py
1 from django import forms 2 from .models import Topic, Entry 3 4 class TopicForm(forms.modelForm): 5 def Meta: 6 model = Topic 7 text = ['text'] 8 labels = {'text': ''} # 不为字段生成标签 9 10 class EntryForm(forms.modelForm): 11 def Meta: 12 model = Entry 13 text = ['text'] 14 labels = {'text': ''} 15 widget = {'text': forms.Textarea(attrs={'cols': 80})}