1for instance in Stock.objects.all():
2 if instance.category == category:
3 raise forms.ValidationError(str(category) + ' is already created')
4 return category
1from django.db.models import Count
2from app.models import Email
3
4duplicate_emails = Email.objects.values('email').annotate(email_count=Count('email')).filter(email_count__gt=1)
5