From: David ‘Bombe’ Roden Date: Thu, 9 May 2013 20:23:01 +0000 (+0200) Subject: Add better many-to-many relationshops for tracks and artists. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b08a5d59143b9d711e7497cbade8598309a8c773;p=demoscenemusic.git Add better many-to-many relationshops for tracks and artists. --- diff --git a/data/admin.py b/data/admin.py index 93a5fef..d957b22 100644 --- a/data/admin.py +++ b/data/admin.py @@ -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) diff --git a/data/models.py b/data/models.py index 33cae30..60e60b3 100644 --- a/data/models.py +++ b/data/models.py @@ -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)