mirror of
https://github.com/django/django.git
synced 2024-11-18 23:44:22 +00:00
d362c1546f
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16976 bcc190cf-cafb-0310-a4f2-bffc1f526a37
36 lines
810 B
Python
36 lines
810 B
Python
# coding: utf-8
|
|
from django.contrib import admin
|
|
from django.db import models
|
|
|
|
|
|
class Band(models.Model):
|
|
name = models.CharField(max_length=100)
|
|
bio = models.TextField()
|
|
rank = models.IntegerField()
|
|
|
|
class Meta:
|
|
ordering = ('name',)
|
|
|
|
class Song(models.Model):
|
|
band = models.ForeignKey(Band)
|
|
name = models.CharField(max_length=100)
|
|
duration = models.IntegerField()
|
|
|
|
class Meta:
|
|
ordering = ('name',)
|
|
|
|
class SongInlineDefaultOrdering(admin.StackedInline):
|
|
model = Song
|
|
|
|
class SongInlineNewOrdering(admin.StackedInline):
|
|
model = Song
|
|
ordering = ('duration', )
|
|
|
|
class DynOrderingBandAdmin(admin.ModelAdmin):
|
|
|
|
def get_ordering(self, request):
|
|
if request.user.is_superuser:
|
|
return ['rank']
|
|
else:
|
|
return ['name']
|