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 :: tessellation 
Python :: convert from R to python 
Python :: copy something character ubntil a specific character in python 
Python :: WARNING: Ignoring invalid distribution -ip (c:python310libsite-packages) 
Python :: input list in function and display column in dataframe python 
Python :: how to set default value in many2one 
Python :: codegrepper is cool 
Python :: python calander from Programmer of empires but updated 
Python :: python goose 
Python :: kill os system by pid python script 
Python :: transpose([[1],[2],[3]]) 
Python :: pomodoro timer in python 
Python :: seewave python 
Python :: ublox kismet 
Python :: tz convert python 
Python :: pytorch get intersection between two masks 
Python :: for loop with 2 variables python 
Python :: Groupby geek link 
Python :: jupyter notebook prevent open browser 
Python :: pandas dtodays date csv 
Python :: find low and high in string 
Python :: custom Yolo object detection python 
Python :: how to convert array of arrays into single array with unique values in numpy 
Python :: python ocr pdf dataframe 
Python :: dask dataframe csv tutorial 
Python :: Pte or Pvt 
Python :: how to write string in python 
Python :: save file in windows hidden folder python 
Python :: fibonacci sequence python genorator 
Python :: how to store svgs in django image field with SVGAndImageFormField 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =