class Post(models.Model):
created_time = models.DateTimeField()
comment_count = models.IntegerField(default=0)
like_count = models.IntegerField(default=0)
group = models.ForeignKey(Group)
class MonthPost(models.Model):
created_time = models.DateTimeField()
comment_count = models.IntegerField(default=0)
like_count = models.IntegerField(default=0)
group = models.ForeignKey(Group)
post = models.OneToOneField(Post)
我使用这两个模型。 MonthPost是Post的一部分。 当过滤日期小于月份时,我想使用MonthPost。django模型中提取OneToOne字段
_models = Model.extra(
select={'score': 'like_count + comment_count'},
order_by=('-score',)
)
我使用额外约两个以上的模型。邮政运作良好,但MonthPost不起作用。
django.db.utils.ProgrammingError: column reference "like_count" is ambiguous
LINE 1: ... ("archive_post"."is_show" = false)) ORDER BY (like_count...
这是错误消息。
_models.values_list("post", flat=True)
然后,我想从MonthPost中提取OneToOne字段(post)。 我尝试使用values_list(“post”,flat = True)。它只返回id列表。 我需要发布django rest框架的对象列表。