开始为将两个模型连接在一起的django模型构建模板/视图

时间:2016-09-21 14:57:48

标签: python django django-forms

我有一个表单,我可以创建和编辑一个组(真正的业务)。虽然我希望能说这个企业有很多地方。我已经写了模型,但UI给了我麻烦。

我认为我的问题主要是通过如何使用单一表单更新Group模型(创建/编辑组)和GroupLocations模型(如果需要,将地址添加为新位置)来解答,因此几乎有三个模型单一表格?

模型是:

class Address(models.Model):
    city = models.CharField(max_length=50)
    state = models.CharField(max_length=50)
    zip_code = models.CharField(max_length=50)
    address_line_one = models.CharField(max_length=50)
    address_line_two = models.CharField(max_length=50,  null=True, blank=True)
    contact = models.CharField(max_length=50, null=True, blank=True)
    phone = models.CharField(max_length=50)
    fax = models.CharField(max_length=50,  null=True, blank=True)
    created_at=models.DateField(auto_now_add=True)
    updated_at=models.DateField(auto_now=True)
    def __str__(self):
        return self.city

class Group(models.Model):
    group_name = models.CharField(max_length=50)
    group_contact= models.CharField(max_length=50)
    tin = models.CharField(max_length=50)
    npi =models.CharField(max_length=50)
    notes = models.TextField(max_length = 255,  null=True, blank=True)
    billing_address = models.ForeignKey('Address', related_name = 'billing_address', on_delete=models.SET_NULL, null=True)
    mailing_address = models.ForeignKey('Address', related_name = 'mailing_address', on_delete=models.SET_NULL,  null=True, blank=True)
    start_date = models.DateField(auto_now=False, auto_now_add=False, null=True, blank=True)
    end_date = models.DateField(auto_now=False, auto_now_add=False, null=True, blank=True)
    change_date = models.DateField(auto_now=False, auto_now_add=False, null=True, blank=True)
    change_text = models.TextField(max_length = 255,  null=True, blank=True)
    term_comment = models.TextField(max_length = 255,  null=True, blank=True)
    group_phone=models.CharField(max_length=50)
    group_fax = models.CharField(max_length=50)
    group_term = models.ForeignKey(GroupTerm, on_delete=models.SET_NULL, null=True, blank=True) #quesiton is can a group be termed many times?
    created_at=models.DateField(auto_now_add=True)
    updated_at=models.DateField(auto_now=True)

    #provider_location = models.ManyToManyField('ProviderLocations', through='GroupLocations')

    def __str__(self):
        return self.group_name

class GroupLocations(models.Model):
    address = models.ForeignKey('Address', on_delete= models.SET_NULL, null=True)
    group = models.ForeignKey('Group', on_delete=models.CASCADE)
    doing_business_as = models.CharField(max_length = 255)
    created_at=models.DateField(auto_now_add=True)
    updated_at=models.DateField(auto_now=True)
    def __str__(self):
        return self.doing_business_as

我希望(对于这个模型和其他人)模仿管理员如何使用漂亮的左右多个选择框来处理用户:(虽然不确定如何添加新位置可能是一个按钮带你到另一种形式,不知何故知道它应该被添加到组中吗?)

enter image description here

我意识到这是一个非常大的问题,我正在寻找大多数我认为如何处理一个表格/模板上的几个模型rails有一个字(这个名字现在让我逃避)并且不确定Django范式是什么是

0 个答案:

没有答案