I have a FieldOfficer model, which has region, team_leader and other attributes.
class FieldOfficer(models.Model):
first_name = models.CharField(max_length=30, blank=False, null=False)
last_name = models.CharField(max_length=30, blank=False, null=False)
team_leader = models.ForeignKey('TeamLead', on_delete=models.SET_NULL, null=True,
related_name="agents")
region = models.CharField(max_length=30, blank=False, null=False)
Additionally, TeamLead and Agent are proxies of the above module.
A TeamLead has many agents, but an agent has one teamlead. An agent should belong to the same region as his TeamLeader.
Upon edit or creation of an agent, i want to enforce the above. ie when i select a teamlead, the agent’s region be the region of the selected team leader. I also want to validate this constraint.
How do i proceed, am using model forms and ModelChoiceField to list all Teamleads available for selection when creating/Updating?