mysql - How to find distinct columns with django? -
i have model this:
class portfolio(models.model): user = models.foreignkey(settings.auth_user_model) project = models.foreignkey(projectdetail, null=true, blank=true) image = models.imagefield(upload_to=get_upload_path, max_length=500, null=true, blank=true) caption = models.charfield(_('caption'), max_length=200, blank=true, null=true) added_on = models.datetimefield(auto_now_add=true) i want find 3 portfolios ordered added_on date distinct user.
i.e.:
portfolio.objects.all().order_by('-added_on').distinct('user')[:3] i know works in postgresql not in mysql, there way accomplish same end result using mysql?
actually .distinct([*fields]) works in postgressql consult distinct documentation can utilize query related this
portfolio.objects.order_by('-added_on').values('user').distinct() consult values docs. hope helps.
mysql django
No comments:
Post a Comment