标签:页面 __str__ price django foreign close isp font ret
l例如写一个图书的管理页面,包括增删改查
首先创建model表
from django.db import models class Book(models.Model): title = models.CharField(max_length=32) price = models.DecimalField(max_digits=8,decimal_places=2) date = models.DateField() publish = models.ForeignKey("Publish",on_delete=models.CASCADE) authors = models.ManyToManyField("Author") def __str__(self): #在admin页面显示中文 return self.title class Publish(models.Model): name = models.CharField(max_length=32) def __str__(self): return self.name class Author(models.Model): name = models.CharField(max_length=32) def __str__(self): return self.name
1 from django.db import models 2 3 class Book(models.Model): 4 title = models.CharField(max_length=32) 5 price = models.DecimalField(max_digits=8,decimal_places=2) 6 date = models.DateField() 7 publish = models.ForeignKey("Publish",on_delete=models.CASCADE) 8 authors = models.ManyToManyField("Author") 9 def __str__(self): #在admin页面显示中文 10 return self.title 11 12 13 class Publish(models.Model): 14 name = models.CharField(max_length=32) 15 def __str__(self): 16 return self.name 17 18 class Author(models.Model): 19 name = models.CharField(max_length=32) 20 def __str__(self): 21 return self.name
标签:页面 __str__ price django foreign close isp font ret
原文地址:https://www.cnblogs.com/ziyoufei/p/12009858.html