how to make django model field case insensitive

Solutions on MaxInterview for how to make django model field case insensitive by the best coders in the world

showing results for - "how to make django model field case insensitive"
Ella
03 Oct 2016
1pip install django_case_insensitive_field
Jacopo
23 Jun 2017
1
2from django.db.models import CharField
3
4from django_case_insensitive_field import CaseInsensitiveFieldMixin
5
6
7class CaseInsensitiveCharField(CaseInsensitiveFieldMixin, CharField):
8    """[summary]
9    Makes django CharField case insensitive \n
10    Extends both the `CaseInsensitiveMixin` and  CharField \n
11    Then you can import 
12    """
13
14    def __init__(self, *args, **kwargs):
15
16        super(CaseInsensitiveMixin, self).__init__(*args, **kwargs) 
17        
18
19from .fields import CaseInsensitiveCharField
20
21
22class UserModel(models.Model):
23
24    username = CaseInsensitiveCharField(max_length=16, unique=True)
25
26user1 = UserModel(username='user1')
27
28user1.save()  # will go through
29
30
31user2 = UserModel(username='User1') 
32
33user2.save() # will not go through
34
similar questions