我想知道如何根据在先前表单字段(公司)中选择的值填充选择字段(联系人和其他联系人)。例如我的表格:
class AddTicketForm(ModelForm):
class Meta:
model = Ticket
fields = (
'issue_type',
'company',
'contact',
'additional_contacts',
'priority',
'subject',
'description',
)
从模型:
class Ticket(models.Model):
issue_type = models.ForeignKey(SubIssueType)
contact = models.ForeignKey(
User,
related_name='ticket_contact',
)
assigned_to = models.ForeignKey(
User,
related_name='ticket_assigned_to',
)
company = models.ForeignKey(
Company,
)
additional_contacts = models.ManyToManyField(
User,
null=True,
blank=True,
)
priority = models.CharField(
'Priority',
max_length=50,
choices = ticket_priority_choices,
)
subject = models.CharField(
'Subject',
max_length=255,
)
description = models.TextField(
'Description',
)
...
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
company = models.ForeignKey(
Company,
)
phone_number = models.CharField(
'Phone Number',
max_length=12,
)
relationship = models.CharField(
'Relationship',
max_length=30,
choices=(
('customer', 'Customer'),
('support', 'Support'),
)
)
...
因此,根据为公司选择的内容,我只想填充作为该公司成员的用户的联系人和附加联系人。这可能与 Django 纯粹有关,还是我需要考虑 JavaScript 来提供帮助?将不胜感激任何指导。