I need create the following relationship:
One "Rule" can have many users, but one user can be only one rule.
Using ForeignKey and a ModelForm, I get a select box to select just ONE user, but I want to select many users. It's not a ManyToMany relationship because one user never can be more than one rule.
Here are my model definitions:
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)
Have some way of to do ir using a ModelForm?