单个表单包含“多个模型”字段,因此如何在UpdateView中将此表单与Django中的多个模型一起使用

时间:2018-08-08 05:47:58

标签: django django-models django-forms django-views

我有三个型号,分别为UserTenantTenantUser。 我想这样输出

Setting.html

但是我不能写视图来显示这个

"models.py "
class Tenant(models.Model):
    name = models.CharField(max_length=100)
    memo = models.TextField(blank=True)
    users = models.ManyToManyField(settings.AUTH_USER_MODEL,
            through='db.TenantUser', blank=True)

    agent_timezone = models.CharField(
        max_length=30, choices=const.AGENT_TIMEZONES)


class TenantUser(models.Model):
    user = 
         models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
    tenant = models.ForeignKey('Tenant', on_delete=models.CASCADE)

    ui_language_code = models.CharField(
          max_length=5, choices=const.UI_LANGUAGE_CODES,
          default=const.UI_LANGUAGE_CODES.japanese)


"forms.py"
from db import const
class EditMemo(forms.Form):
    agent_timezone = forms.ChoiceField(choices=const.AGENT_TIMEZONES)
    memo = forms.CharField(widget=forms.Textarea)
    ui_language_code = forms.ChoiceField(choices=const.UI_LANGUAGE_CODES)

"Views.py"
class AccountSettingsView(LoginRequiredMixin,UpdateView):
    # views Code here that can update two models tanant and tanantUser

0 个答案:

没有答案