Multiple ManyToManyField in 2 classes in Django

Viewed 22

I am having an error related with Manytomanyfield:

NameError: name 'Illness' is not defined 

I have 2 classes with ManyToManyField realtionship bettween them:

class Pair(models.Model):
    id = models.AutoField(primary_key = True)
    name = models.CharField(max_length=60)
    description = models.TextField()
    illness = models.ManyToManyField(Illness, blank=True)
    
class Illness(models.Model):
    name = models.CharField(max_length=60)
    description = models.TextField()
    pair = models.ManyToManyField(Pair, blank=True)

And of course if I write Class Illness first then the error is:

NameError: name 'Pair' is not defined.

Anyone knows how to solve this issue?

Thanks!

0 Answers
Related