I have the following model in Django:
class Bout (models.Model):
fighter_1 = models.ForeignKey(Fighter, related_name="bout_fighter_1")
fighter_2 = models.ForeignKey(Fighter, related_name="bout_fighter_2")
winner = models.ForeignKey(Fighter, related_name="bout_winner",
blank=True, null=True, help_text='Leave blank for draw.')
date = models.DateField()
cancelled = models.BooleanField()
I would like to "idiot-proof" the administration for its records. Incidently, I want to create three rules:
Fighter 1 is not the same as fighter 2 (which is only good for a monty python skit).
Winner should be in the bout (i.e., either Fighter 1 or Fighter 2)
The winner can't be set before the match takes place. (After all, this isn't WWE.)
All three of these rules require checking one field against another field in the same record. Is it possible to do this in django, either using native django methods or resorting to python?