Django 元管理排序 - 排除语法文章
我目前有这样的模型代码块:
class Book(models.Model):
title = models.CharField(max_length=100)
num_pages = models.IntegerField(blank=True, null=True)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()
def __unicode__(self):
return self.title
class Meta:
ordering = ["title"]
如果我有一本名为“The Fry Chronicles”或“A Hitchhikers Guide to the Galaxy”(例如)的书名,则为有没有办法让 Django 忽略管理界面中单词之前的那些短文章(an、a、the 等),而只按文章后面的单词对结果进行排序?
更进一步,也许有一种方法可以像这样排列结果......
- 弗莱编年史,
- 银河系漫游指南,A
至于将文章移到书名的末尾吗?
有人可以提出解决上述两个问题的方案吗?
提前致谢!
I currently have this chunk of model code:
class Book(models.Model):
title = models.CharField(max_length=100)
num_pages = models.IntegerField(blank=True, null=True)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()
def __unicode__(self):
return self.title
class Meta:
ordering = ["title"]
If I have a book title called 'The Fry Chronicles' or 'A Hitchhikers Guide to the Galaxy' (for example), is there a way to get Django to ignore those short articles (an, a, the etc.) before the word within the admin interface, and just order the results by the words that follows the article?
To take it a step further, maybe there is a way to lay out the results like this...
- Fry Chronicles, The
- Hitchhikers Guide to the Galaxy, A
As to move the article to the end of the book title?
Could anybody propose a solution to the above two issues?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试,
并且只需确保在存储之前解析
ordered_title
即可。You could try,
And just make sure that you are parsing
ordered_title
before you store it.我认为如果不破解内部 django 管理代码,这是不可能的。
不过,如果冗余不是问题,您可以采取一些小技巧。 Book 中有额外的字段,表示订购的标题(如
clean_title
)和使用ordering
管理中的属性。I don't think this is possible without hacking internal django admin code.
You can however do a little trick if some redundancy is not a problem. Have additional field in Book that represents title for ordering (like
clean_title
) and the useordering
attribute in admin.不知道这是否有效...未经测试...只是一个想法,请记住 django 只是 python...我希望这有助于让您走上正轨!?!
Don't know if this is working....untested...just an idea to keep in mind that django is just python...I hope that helps to get you to the right track!?!