我有一个模型如下:
class talk(models.Model):
...
speakers = models.ManyToManyField('speaker')
...
与型号有关speaker
class speaker(models.Model):
name = models.CharField(max_length=255)
email = models.CharField(max_length=255)
...
我想talk
按字母顺序对课堂上的演讲者进行排序,所以speakers['charlie', 'bill', 'andy']
变成speakers['andy', 'bill', 'charlie']
.
完成后,我的课程talkAdmin
如下所示:
class talkAdmin(admin.ModelAdmin):
readonly_fields = ('slug',)
list_display = ['title', 'speakers', 'date']
search_fields = ['title', 'speakers']
这目前不起作用,因为list_display
不接受 ManyToManyField。我想做的是在扬声器中获取每个对象并将其显示在它自己的列中。
-------------------------------------------------
|Talk |Speaker |Second Speaker|Third Speaker|
|Django |Andy |Bill |Charlie |
-------------------------------------------------
这可能吗?