[Python] How to delete first N items from queryset in django

Discussão em 'Python' iniciado por Stack, Agosto 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm looking to delete only the first N results returned from a query in django. Following the django examples here which I found while reading this SO answer, I was able to limit the resulting set using the following code

    m = Model.objects.all()[:N]


    but attempting to delete it generates the following error

    m.delete()
    AssertionError: Cannot use 'limit' or 'offset' with delete.


    Is there a way to accomplish this in django?

    Continue reading...

Compartilhe esta Página