I am using django.core.serializers
to serialise my Queryset and then return it as JSON later on.
from django.core import serializers
from .models import MyModel
def a_view(request):
objects = MyModel.objects.all()
serializers.serialize('json', objects, indent=2, use_natural_foreign_keys=True, use_natural_primary_keys=True)
Let's say MyModel has MyModel.data
, which is a ManyToManyField
that could have thousands of relations. I would like to only get the latest X objects of MyModel.data in this case.
How would I do this?