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