[Django]-Model Many to Many relations with Abstract Class

8👍

Sounds like you’re ready for polymorphism:

https://django-polymorphic.readthedocs.org

Otherwise you’ll have to add them individually, so your Institution model would look something like this:

class Institution(models.Model):
    name = models.CharField(_('Name'), max_length=150, db_index=True)
    slug = models.SlugField(_('Domain name'), unique=True)

    class Meta:
        abstract = True

and the manytomany just basic like this:

following_company = models.ManyToManyField(Company, blank=True, null=True)
following_hc = models.ManyToManyField(Institution, blank=True, null=True)

Leave a comment