Add better many-to-many relationshops for tracks and artists.
authorDavid ‘Bombe’ Roden <bombe@demoscenemusic.org>
Thu, 9 May 2013 20:23:01 +0000 (22:23 +0200)
committerDavid ‘Bombe’ Roden <bombe@demoscenemusic.org>
Thu, 9 May 2013 20:23:01 +0000 (22:23 +0200)
data/admin.py
data/models.py

index 93a5fef..d957b22 100644 (file)
@@ -6,5 +6,22 @@ admin.site.register(Group)
 admin.site.register(Party)
 admin.site.register(Compo)
 admin.site.register(Release)
-admin.site.register(Track)
 admin.site.register(File)
+
+class TrackArtistInline(admin.TabularInline):
+       model = TrackArtist
+       extra = 1
+
+class RemixArtistInline(admin.TabularInline):
+       model = RemixArtist
+       extra = 1
+
+class TrackAdmin(admin.ModelAdmin):
+       fieldsets = [
+               (None, {'fields': ['name', 'length']}),
+               ('Remix Information', {'fields': ['remix'], 'classes': ['collapse']}),
+               ('Release Information', {'fields': ['releases']}),
+       ]
+       inlines = [TrackArtistInline, RemixArtistInline]
+
+admin.site.register(Track, TrackAdmin)
index 33cae30..60e60b3 100644 (file)
@@ -35,16 +35,26 @@ class Release(models.Model):
        year = models.IntegerField()
        compo = models.ForeignKey(Compo)
        place = models.IntegerField()
-       pouetId = models.IntegerField(blank = True)
+       pouetId = models.IntegerField(blank = True, null = True)
 
        def __unicode__(self):
                return self.compo.__unicode__() + ' @ ' + self.party.__unicode__() + ' ' + '%d' % self.year
 
+class TrackArtist(models.Model):
+       track = models.ForeignKey('Track')
+       artist = models.ForeignKey(Artist)
+       order = models.IntegerField()
+
+class RemixArtist(models.Model):
+       track = models.ForeignKey('Track')
+       artist = models.ForeignKey(Artist)
+       order = models.IntegerField()
+
 class Track(models.Model):
        name = models.CharField(max_length = 150)
-       artists = models.ManyToManyField(Artist)
+       artists = models.ManyToManyField(Artist, through = TrackArtist)
        remix = models.CharField(max_length = 80, blank = True)
-       remixArtists = models.ManyToManyField(Artist, related_name = 'remixTracks', blank = True)
+       remixArtists = models.ManyToManyField(Artist, through = RemixArtist, related_name = 'remixTracks')
        releases = models.ManyToManyField(Release)
        length = models.IntegerField()
        soundcloudLink = models.CharField(max_length = 150, blank = True)