我有以下内容:
class Product(models.Model):
name = models.CharField(max_length=255)
class Action(models.Model):
product = models.ForeignKey(Product)
created_at = models.DateTimeField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)
我想检索created_at DESC使用不同产品订购的10个最新动作.
以下是接近结果,但仍然错过了顺序:
Action.objects.all().order_by('product_id').distinct('product_id')[:10]
Run Code Online (Sandbox Code Playgroud)