Rewriting This Database Access Query To Circumvent 'DISTINCT ON' Error, In Django
I have two very simple models: class Link(models.Model): description = models.TextField(validators=[MaxLengthValidator(500)]) submitter = models.ForeignKey(User) submit
Solution 1:
You could just take care of the distinct
in memory.
replies_by_link = {}
replies = Publicreply.objects.filter(answer_to_id__in=link_ids).order_by('answer_to', 'submitted_on')
for reply in replies:
if reply.answer_to_id not in replies_by_link:
replies_by_link[reply.answer_to_id] = reply
and then you can access all the replies via replies_by_link.values()
.
Post a Comment for "Rewriting This Database Access Query To Circumvent 'DISTINCT ON' Error, In Django"