app01model.py
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
from django.db import models # Create your models here. class Depart(models.Model): id = models.AutoField(primary_key=True) title = models.CharField(verbose_name="部门名称", max_length=32) class UserInfo(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(verbose_name="用户名", max_length=32) pwd = models.CharField(verbose_name="密码", max_length=16) age = models.IntegerField(verbose_name="年龄", max_length=3) depart = models.ForeignKey(verbose_name="部门", to="Depart", to_field="id", on_delete=models.CASCADE)
app02model.py
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
from django.db import models # Create your models here. class Host(models.Model): '''主机表''' id = models.AutoField(primary_key=True) host = models.CharField(verbose_name="主机名", max_length=32) ip = models.GenericIPAddressField(verbose_name="IP", protocol="both") # 支持ipv4 和 ipv6
如何完成这三张表的增删改查:
为app中每个 model类, 自动创建 URL 以及函数:
直接放几张图:
自动生成url的类:
app中:
根路由:
然后直接页面看。是不是生成了,这么多的 url:
不要在意错误!!看是不是有了这个多的 url 。 事实整明!此法可行!