标签:modelform
直接上代码:
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
标签:modelform
原文地址:http://13020688.blog.51cto.com/13010688/1941359