django find duplicate records and delete duplicate records code example
Example 1: how to avoid inserting duplicate records in orm django
if not table.objects.filter(column1=values).exists():
# Insert new data here
table.objects.create(column1=v1, column2=v2)
Example 2: django prevent duplicate entries
for instance in Stock.objects.all():
if instance.category == category:
raise forms.ValidationError(str(category) + ' is already created')
return category