다음과 같은 관계를 만들어야합니다.ModelForm을 OneToMany 관계
"규칙"하나는 많은 사용자를 가질 수 있지만 한 사용자는 하나의 규칙 일 수 있습니다.
ForeignKey와 ModelForm을 사용하여 하나의 사용자 만 선택할 수있는 선택 상자가 표시되지만 많은 사용자를 선택하려고합니다. 한 사용자가 둘 이상의 규칙이 될 수 없기 때문에 ManyToMany 관계가 아닙니다.
class User(models.Model):
name = models.CharField(_(u'Nome do usuário'), max_length=20)
password = models.CharField(_('Senha'), max_length=20)
active = models.BooleanField(default=True)
def __unicode__(self):
return self.name
class Rule(models.Model):
ACTIONS = (
('liberate', 'Liberar'),
('block', 'Bloquear'),
)
users = models.ForeignKey(User)
description = models.CharField(_(u'Descrição'), max_length=30)
extensions = models.TextField(_(u'Extensões'), blank=True)
words = models.TextField(_(u'Palavras'), blank=True)
domains = models.TextField(_(u'Domínios'), blank=True)
time = models.TimeField(_(u'Horário'))
action = models.CharField(_(u'Ação'), max_length=8, choices=ACTIONS)
이 ModelForm를 사용하여 IR 수행하는 몇 가지 방법이 : 여기
내 모델 정의입니까?
모델 정의를 붙여 넣습니다. 당신이 방금 잘못된 모델과의 관계를 만든 것처럼 들리더라도. –