1for instance in Stock.objects.all():
2 if instance.category == category:
3 raise forms.ValidationError(str(category) + ' is already created')
4 return category
1if not table.objects.filter(column1=values).exists():
2 # Insert new data here
3 table.objects.create(column1=v1, column2=v2)
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