0
我已经得到了有三个简单的模型定义一个简单的Django摄影大赛应用:Django管理:订购内嵌基于FK'd财产
class Person(models.Model):
name = models.CharField(unique=True, max_length=255)
id = models.AutoField(primary_key=True)
class Meta:
db_table = u'people'
def __unicode__(self):
return self.name
class Round(models.Model):
theme = models.CharField(max_length=255)
number = models.IntegerField()
id = models.AutoField(primary_key=True)
class Meta:
db_table = u'rounds'
def __unicode__(self):
return self.season.name+" - "+self.theme
class Entry(models.Model):
rank = int
total_score = models.SmallIntegerField()
id = models.AutoField(primary_key=True)
person = models.ForeignKey(Person, db_column='person')
round = models.ForeignKey(Round, db_column='round')
一个Round
有多个Entry
对象,每个Entry
有一个Person
。其中一个Person
明显可以有多个Entrys
分成不同的Rounds
。
在管理视图中,我希望能够选择一个Round
并在线查看Entry
项的详细信息。这个我可以用下面的操作:
class EntryInline(admin.TabularInline):
model = Entry
fields = ['comments','person','total_score','image']
readonly_fields = ['person','image']
extra = 0
class RoundAdmin(admin.ModelAdmin):
fields = ['theme','number']
inlines = [EntryInline]
然而,这种看似随意排序Entry
。我可以在EntryInline
类中使用django的新ordering
关键字来指定应该在该人上的顺序,但是该顺序由人Id
属性而不是它们的name
属性。
如何在FK'd Person.name
上订购此内容?
现在似乎是显而易见的:) – growse