V
V
Vladimir Kuts2018-04-13 17:51:55
Django
Vladimir Kuts, 2018-04-13 17:51:55

Add your object to the request?

There is an API like this:

class SomeList(ListAPIView):

    serializer_class = SomeListSerializer
    paginate_by = 5

    def get_queryset(self):
        return SomeModel.objects.filter(somefilter).order_by('-date')

everything is displayed, everything is fine, but it was necessary to insert at the end of the list of objects that are obtained from get_queryset, an object not related to SomeModel, which has the same fields as the request objects (in order to serialize correctly), but not stored in the database, but custom.
How to do this with the least bloodshed, without breaking pagination and so on?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Barabanov, 2018-04-14
@reb00ter

as an option - you can override get_context_data and conjure there, carefully making a list from the QuerySet first

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question