直接上代码:
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']
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。