2010-12-12 22:56:01 +00:00
|
|
|
from django.contrib import admin
|
2011-10-13 18:51:33 +00:00
|
|
|
from django.db import models
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
|
|
|
|
class Band(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
bio = models.TextField()
|
|
|
|
rank = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
2022-02-03 19:24:19 +00:00
|
|
|
ordering = ("name",)
|
2010-12-12 22:56:01 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-12-12 22:56:01 +00:00
|
|
|
class Song(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
band = models.ForeignKey(Band, models.CASCADE)
|
2010-12-12 22:56:01 +00:00
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
duration = models.IntegerField()
|
2022-02-03 19:24:19 +00:00
|
|
|
other_interpreters = models.ManyToManyField(Band, related_name="covers")
|
2010-12-12 22:56:01 +00:00
|
|
|
|
|
|
|
class Meta:
|
2022-02-03 19:24:19 +00:00
|
|
|
ordering = ("name",)
|
2010-12-12 22:56:01 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-12-12 22:56:01 +00:00
|
|
|
class SongInlineDefaultOrdering(admin.StackedInline):
|
|
|
|
model = Song
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-12-12 22:56:01 +00:00
|
|
|
class SongInlineNewOrdering(admin.StackedInline):
|
|
|
|
model = Song
|
2022-02-03 19:24:19 +00:00
|
|
|
ordering = ("duration",)
|
2011-06-12 13:04:53 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-06-12 13:04:53 +00:00
|
|
|
class DynOrderingBandAdmin(admin.ModelAdmin):
|
|
|
|
def get_ordering(self, request):
|
|
|
|
if request.user.is_superuser:
|
2022-02-03 19:24:19 +00:00
|
|
|
return ["rank"]
|
2011-06-12 13:04:53 +00:00
|
|
|
else:
|
2022-02-03 19:24:19 +00:00
|
|
|
return ["name"]
|