Last active
January 4, 2016 03:49
-
-
Save joequery/8564118 to your computer and use it in GitHub Desktop.
Django - Delete data for all models of a single app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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