[Answered ]-How to make a Model with a Many-to-Many relationship as Categories (i.e) rock ,Country, Blues, and Pop

2๐Ÿ‘

โœ…

I think what you want to do is define Category as a Model with a Many-to-Many relationship with Album. That way, you can do things like: Album.objects.filter(category__name='country') or you could take an instance of Category and do category.album_set.all()

Try this above your Album model:

class Category(models.Model):
    name = models.CharField(max_length=50)
    desc = models.TextField()

Then add to your Album model:

category = models.ManyToManyField(Category)
๐Ÿ‘คperfect5th

Leave a comment