1👍
Have you tried filtering on field_name__iexact, to do a case insensitive match?
The iregex, icontains and iexact filters should be able to do what you need.
0👍
First off, you can user the clean for this functionality (triggered when trying to validate a form):
def clean__field_name(self):
Also, you can add a unique=True
constraint to the field in question. Then do a Try/Except
during save to catch any IntegrityError
which will tell you that the field is not unique. The database and model should do this work for you instead of trying to code around it.
Also see Case insensitive unique model fields in Django?
With more detail (database type, copy of model, are you using a Form?), I can expand on this answer.
- Using Aldryn Apphooks Config
- Django update an instance using another instance
- Values list vs Iterating
- Formulating an efficient DB query with highly challenging requirements (Django app)
Source:stackexchange.com