Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make django model field case insensitive

pip install django_case_insensitive_field
Comment

how to make django model field case insensitive


from django.db.models import CharField

from django_case_insensitive_field import CaseInsensitiveFieldMixin


class CaseInsensitiveCharField(CaseInsensitiveFieldMixin, CharField):
    """[summary]
    Makes django CharField case insensitive 

    Extends both the `CaseInsensitiveMixin` and  CharField 

    Then you can import 
    """

    def __init__(self, *args, **kwargs):

        super(CaseInsensitiveMixin, self).__init__(*args, **kwargs) 
        

from .fields import CaseInsensitiveCharField


class UserModel(models.Model):

    username = CaseInsensitiveCharField(max_length=16, unique=True)

user1 = UserModel(username='user1')

user1.save()  # will go through


user2 = UserModel(username='User1') 

user2.save() # will not go through
Comment

django model make the field caseinsensitive

def clean(self):
        self.name = self.name.capitalize()
Comment

PREVIOUS NEXT
Code Example
Python :: templateDoesNotExist Django 
Python :: two for loops in list comprehension 
Python :: python group by multiple aggregates 
Python :: how to append a number to a list in python 
Python :: conda python update 
Python :: python push to list 
Python :: f string in python 
Python :: seaborn pairplot 
Python :: how to get unique value of all columns in pandas 
Python :: groupby count pandas 
Python :: find substr within a str in python 
Python :: delete an element by value from a list if it made of white spaces python 
Python :: argparse required arguments 
Python :: django drop all tables 
Python :: get instance of object python 
Python :: get mode dataframe 
Python :: limit for loop python 
Python :: delete one pymongo 
Python :: python get last element of list 
Python :: .text python 
Python :: count number of spaces in string python 
Python :: change django time zone 
Python :: check pyenv version windows 
Python :: how to do disconnect command on member in discord python 
Python :: find character in python 
Python :: python package version in cmd 
Python :: list of seaborn color palette 
Python :: python regular expression remove numbers 
Python :: delete database entry using name django 
Python :: python find in list 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =