Skip to main content

Django Case Insensitive Field is used to make Django Model Field case insensitive - by default Django can't do this.

Project description

Django Case Insensitive Model Field

pip install django_case_insensitive_field

With Django Case Insensitive Field you can make Django Model Field case insensitive - by default Django can't do this which will make it impossible to add a unique field that will be case insensitive regardeless of case.

Let's assume you have a username field on your UserModel which ofcourse would require username to be unique accross the table but to Django abc is different from ABC because it is case sensitive (meaning: users can use the same username but with different case).

Look at the example below:

from django.db import models

class UserModel(models.Model):

    username = models.CharField(max_length=16, unique=True)



user1 = UserModel(username='user1')

user1.save()  # will go through

user2 = UserModel(username='User1') # will still go through

user2.save()  # will go through

Using Django Case Insensitive Model

To make Django Model Field insensitive, you can use the code below:

No need for installation ot inclusion in app.

# fields.py

from django.db.models import CharField

from django_case_insensitive_field import CaseInsensitiveFieldMixin


class CaseInsensitiveCharField(CaseInsensitiveFieldMixin, CharField):
    """[summary]
    Makes django CharField case insensitive \n
    Extends both the `CaseInsensitiveMixin` and  CharField \n
    Then you can import 
    """

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

        super(CaseInsensitiveMixin, self).__init__(*args, **kwargs) 
# models.py

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

Note:

All values are converted to lowercase before insertion and extraction from database.

Compatibility

  1. Compatible with every database - POSTGRESQL, SQLITE, MYSQL etc.
  2. Compatible with Django 2+, 3+

Dependencies

Holla! No dependecy. Lightweight!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_case_insensitive_field-1.0.6.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_case_insensitive_field-1.0.6-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file django_case_insensitive_field-1.0.6.tar.gz.

File metadata

File hashes

Hashes for django_case_insensitive_field-1.0.6.tar.gz
Algorithm Hash digest
SHA256 2b1003f59532054ec037418fea2235d8c6da6241b01b9bfb7b77cad995e06596
MD5 a722987d1acb32742afd97b708f15da2
BLAKE2b-256 cdc2176759d9af72d7fe90cffde4f85416f6dae9fa958914fb68c3351d71d373

See more details on using hashes here.

File details

Details for the file django_case_insensitive_field-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_case_insensitive_field-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6de6f40c664ac1f2b1021f5fba57f0d6d1c0cae7bdbc375a666346249fffbc7a
MD5 9b828b386377e81932117545c75ed327
BLAKE2b-256 9195e711d1687131a09b566dd440adeb084310591ecdf541c59e2fe4da7f5d27

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page