我有模特:
class News(models.Model):
title = ...
content = ...
creationdate = models.DateTimeField(default=datetime.now)
[etc]
class Model_A(models.Model):
name = ...
info = ...
news = models.ManyToManyfield(News)
[etc]
class Model_B(models.Model):
field_b = ...
info = ...
news = models.ManyToManyfield(News)
[etc]
我想从model_a和model_b获取新闻,按createdate排序。怎么做?
答案 0 :(得分:0)
假设您有model_a_inst
作为Model_A
的对象之一
model_a_inst.news.all().order_by('creationdate')