Answer the question
In order to leave comments, you need to log in
How to work with ManyToManyField Django?
How to get a choice from one to several Contractors (owner) from the "Technical support" group, in the selection field in the application in the admin panel.
Now I can set it up only to receive one, and no more, performers.
Used ForeignKey:
class Application(models.Model):
...
owner = models.ForeignKey(User, null = True, blank = True, limit_choices_to={ 'groups__name': 'Техническая поддержка'})
class Owner(models.Model):
executor = models.ForeignKey(User, null = True, blank = True, limit_choices_to={ 'groups__name': 'Техническая поддержка'})
class Application(models.Model):
...
owner = models.ManyToManyField(Owner, verbose_name = 'Исполнитель')
Answer the question
In order to leave comments, you need to log in
I don’t know what kind of fields you have there in the model, but here is an example:
class Owner(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return '{0}'.format(self.short_name)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question