使用Django Admin界面,如何确保HTML select multiple中的对象按某种顺序排序(最好是按字母顺序)?问题在于我有3个模型-CD、Song、Singer。在CD管理员仪表板上,Song是CD的内联,并且Singer是一个希望排序的manytomany字段!
我的model.py文件:
我的model.py文件:
class CD(models.Model):
cd_name = models.CharField("CD Name",max_length=50)
date = models.DateField("CD Release Date")
photo = models.ImageField("CD Cover",blank=True,upload_to='covers')
singers = models.ManyToManyField(Singer,blank=True,null=True)
def __unicode__(self):
return self.cd_name
class Song(models.Model):
cid = models.ForeignKey(CD)
track_num = models.PositiveIntegerField("Track Number",max_length=2)
song_name = models.CharField("Song Name",max_length=50)
soloists = models.ManyToManyField(Singer,blank=True,null=True)
stream_url = models.URLField("Stream URL", blank=True)
def __unicode__(self):
return self.song_name
class Singer(models.Model): (not relevent)
我的admin.py
文件:
class SongInline(admin.TabularInline):
model = Song
extra = 0
class CDAdmin(admin.ModelAdmin):
list_display = ('cd_name', 'date')
inlines = [
SongInline,
]
admin.site.register(CD, CDAdmin)
formfield_for...
仍然是直接从文档中获取的。谢谢。 - Yuji 'Tomita' Tomita