database design - Django many to many relations -


i have 3 models, i'm not sure how design best. 1 song model, 1 artist , show model

class artist(models.model):     name = models.charfield(max_length=255)     label = models.charfield(max_length=255, null=true)      def __str__(self):         return self.name  class show(models.model):     name = models.charfield(max_length=255)      def __str__(self):         return self.name   class song(models.model):     title = models.charfield(max_length=255)     artist = models.manytomanyfield('artist')     show = models.manytomanyfield('show')     duration = models.floatfield()      def __str__(self):         return '%s - %s (%s)' % (self.title, [artist.name artist in self.artist.all()], self.duration) 

the things wasn't sure relations. artist has songs, song can have multiple artists, , show can (or has) multiple songs , songs can in multiple shows essentially. right design here manytomany fields?

on database level it's pretty obvious: artist (m:n) song (m:n) show. implements situations described , assumes artist participating in show through singing song (he can not participate without performing something).

the model go this:

class artist(models.model):     songs = models.manytomanyfield('song')  class song(models.model):     artists = models.manytomanyfield('artist')     shows = models.manytomanyfield('show')  class show(models.model):     songs = models.manytomanyfield('song') 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -