From b08a5d59143b9d711e7497cbade8598309a8c773 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 9 May 2013 22:23:01 +0200 Subject: [PATCH] Add better many-to-many relationshops for tracks and artists. --- data/admin.py | 19 ++++++++++++++++++- data/models.py | 16 +++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) 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) -- 2.7.4