【Django】简单的图书管理系统
作者:互联网
目录
1.数据准备
class Book(models.Model):
"""图书表"""
title = models.CharField(max_length=32)
price = models.DecimalField(max_digits=8, decimal_places=2)
publish_time = models.DateField(auto_now=True)
publish = models.ForeignKey(to='Publish', on_delete=models.CASCADE)
authors = models.ManyToManyField(to='Author')
def __str__(self):
return f'图书对象:{self.title}'
class Publish(models.Model):
"""出版社表"""
name = models.CharField(max_length=32)
address = models.CharField(max_length=64)
def __str__(self):
return f'出版社对象{self.name}'
class Author(models.Model):
"""作者表"""
name = models.CharField(max_length=32)
age = models.IntegerField()
author_detail = models.OneToOneField(to='AuthorDetail',on_delete=models.CASCADE)
def __str__(self):
return f'作者对象{self.name}'
class AuthorDetail(models.Model):
"""作者详情表"""
phone = models.BigIntegerField()
address = models.CharField(max_length=64)
def __str__(self):
return f'作者详情对象{str(self.phone)}|{self.address}'
2.首页搭建
3.书籍展示
4.书籍添加
5.书籍编辑
6.书籍删除
标签:__,管理系统,models,max,self,Django,CharField,书籍,图书 来源: https://www.cnblogs.com/cainiaozhy/p/16667423.html