Django建议为ManyToMany模型字段创建视图

时间:2019-05-28 12:02:06

标签: django django-forms django-templates

我有3个模型,它们具有2个多边关系字段...现在我必须制作views.py函数和模板。我想用django admin中生成的内容做模板相似,但是我不知道如何。

我将发布models.py结构

from app_name.models import Person, Admin
from another_app.models import ListB, SchTrat, ListM

class A(models.Model):
    data_create_a = models.DateTimeField(auto_now_add=True)
    data_modify_b = models.DateTimeField(auto_now=True)
    cant = models.CharField(max_length=100)
    days = models.CharField(max_length=100)
    mod = models.CharField(max_length=100, choices=MOD)
    sch = models.ForeignKey(SchTrat, on_delete=models.PROTECT)
    list_m = models.ForeignKey(ListM, on_delete=models.PROTECT)

class B(models.Model):
    data_create_b = models.DateTimeField(auto_now_add=True)
    data_modify_b = models.DateTimeField(auto_now=True)
    type = models.CharField(max_length=100, choices=TYPE)
    list_b = models.ForeignKey(ListaB, on_delete=models.PROTECT)
    **med = models.ManyToManyField(A)**

class C(models.Model):
    data_create_c = models.DateTimeField(auto_now_add=True)
    data_modify_c = models.DateTimeField(auto_now=True)
    simpt = models.CharField(max_length=100)
    tens = models.CharField(max_length=100)
    mm = models.CharField(max_length=100)
    temp = models.CharField(max_length=100)
    height = models.CharField(max_length=100)
    weight = models.CharField(max_length=100)
    glic = models.CharField(max_length=100)
    AV = models.CharField(max_length=100)
    **person = models.ForeignKey(Person, on_delete=models.CASCADE)**
    admin = models.ForeignKey(Admin, on_delete=models.PROTECT)
    **diag = models.ManyToManyField(B)**

我希望在模板中添加一个新的C(models.Model)并具有插入多个B(models.Model)和多个A(models.Model)的可能性,并具有在该新C中插入的内容的可能性(models.Model),然后再提交C(models.Model)。

谢谢!

0 个答案:

没有答案