Search code examples
djangopostgresqldjango-modelssql-delete

Django - delete recently created objects across database


Is there a way to delete like, all the objects that have been created in the last 10 mins across all the models? Or atleast across 1 model? Unfortunately, I am not storing any created field in those models.

Database - Postgresql


Solution

  • Django id's are auto-incrementing. So, if we know the id of the last object created before the problem, we can simply do -

    Model.objects.filter(id__gt=last_id).delete()
    

    It is not the ideal solution, but works for now.