I’m trying to link a model to two fields in a separate model using foreign keys. This is giving the error:
<class 'actionlog.admin.ActionInstanceInline'>: (admin.E202) 'actionlog.Action' has more than one ForeignKey to 'actionlog.Audit'.
Searching through posts shows this is a common problem resolved by using a related name for at least one field. However, I’m still getting this error. Must be something dumb but I’d appreciate help working out what I’ve done wrong.
The models are as follows:
class Audit(models.Model): audit_ref = models.CharField(max_length=5, help_text='Unique audit ref YY_xx, e.g. 21_01 (max length 5 chars)') audit_name = models.CharField(max_length=40, help_text='Audit name (max length 40 chars)') lead_auditor = models.ForeignKey('LeadAuditor', on_delete=models.SET_NULL, null=True)
class Action(models.Model): action_ref = models.CharField(max_length=3, help_text='Action ref e.g. 01 or 12b (max 3 chars)') action_title = models.CharField(max_length=100, help_text='Action title (max 100 chars)') audit_ref = models.ForeignKey('Audit', on_delete=models.CASCADE) lead_auditor = models.ForeignKey('Audit', on_delete=models.CASCADE, related_name='lead_auditors')