Created
July 26, 2017 08:36
-
-
Save jmorenoamor/4ee70646b809e75516ba557286807f56 to your computer and use it in GitHub Desktop.
Find duplicate models using Django ORM
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 apps.projects.models import Project | |
from django.db.models import Count | |
# Find duplicated models based on the value of one or more fields | |
dupes = Project.objects.values('name').annotate(Count('id')).order_by().filter(id__count__gt=1) | |
dupes = Project.objects.values('name', 'code').annotate(Count('id')).order_by().filter(id__count__gt=1) | |
dupes = Project.objects.values('name', 'code', 'release').annotate(Count('id')).order_by().filter(id__count__gt=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment