Skip to content

Instantly share code, notes, and snippets.

@joequery
Last active January 4, 2016 03:49
Show Gist options
  • Select an option

  • Save joequery/8564118 to your computer and use it in GitHub Desktop.

Select an option

Save joequery/8564118 to your computer and use it in GitHub Desktop.
Django - Delete data for all models of a single app
from django.contrib.contenttypes.models import ContentType
cts = ContentType.objects.filter(app_label="article")
for ct in cts:
TheModel = ct.model_class()
records = TheModel.objects.all()[:100]
while records:
pks = [r.pk for r in records]
TheModel.objects.filter(pk__in=pks).delete()
records = TheModel.objects.all()[:100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment