Defining abstract base model that can be referenced in another model in Django
Having these models in Django. Album and Playlist as song collections. Library consists of playlists and albums. After I defined base model to hold some common fields of Album and Playlist, some complications occured:
class Collection(models.Model):
title = models.CharField(max_length=64)
release_date = models.DateField()
class Meta:
abstract = True
class Album(Collection):
pass
class Playlist(Collection):
is_public = models.BooleanField(default=True)
is_liked_songs_playlist = models.BooleanField(default=False)
description = models.TextField(blank=True)
class Library(models.Model):
collections = models.ManyToManyField("Collection", related_name="libraries")
# playlists = models.ManyToManyField("Playlist", related_name="libraries")
# albums = models.ManyToManyField("Album", related_name="libraries", blank=True)
This code errors since Collection is abstract. Is is possible to change somehow that so that works without changing Collection from abstract to regular? I do not want Collection model has its own table in db. Maybe I need to change type of relation from ManyToManyField to some other? Please advice