django Form模块实例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了django Form模块实例相关的知识,希望对你有一定的参考价值。
直接上代码:
models.py
from django.forms import ModelForm from django.db import models TITLE_CHOICES = ( ("MR","Mr.‘), ("MRS","Mrs."), ("MS",‘Ms."), ) class Author(models.Model): name = models.CharField(max_length=100) title = models.CharField(max_length=3,choices=TITLE_CHOICES) birth_date = models.DateField(blank=True,null=True) def __str__(self): return self.name class Book(models.Model): name = models.CharField(max_length=100) authors = models.ManyToManyField(Author) class AuthorForm(ModelForm): class Meta: model = Author fields = [‘name‘,‘title‘,‘birth_date‘] class BookForm(ModelForm): class Meta: model = book fields = [‘name‘,‘authors‘]
本文出自 “13010688” 博客,请务必保留此出处http://13020688.blog.51cto.com/13010688/1941359
以上是关于django Form模块实例的主要内容,如果未能解决你的问题,请参考以下文章