Skip to main content

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(CaseInsensitiveFieldMixin, 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!

Metadata

Release files for django-case-insensitive-field 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-case-insensitive-field 1.0.7
File Size Uploaded Provenance Actions
django_case_insensitive_field-1.0.7.tar.gz 3.6 kB Without provenance Details for django_case_insensitive_field-1.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-case-insensitive-field 1.0.7
File Interpreter ABI Platform Actions
django_case_insensitive_field-1.0.7-py3-none-any.whl Python 3 none any Details for django_case_insensitive_field-1.0.7-py3-none-any.whl

Total release size: 7.2 kB

Release files / django_case_insensitive_field-1.0.7.tar.gz

Download URL django_case_insensitive_field-1.0.7.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8e2502a932cf50a727abecc73a141edb75f740933ebbf5ae8745bcfadd9c3029
BLAKE2b-256 checksum
How to use checksums
9618d77815f85a2ac0f0188a0a80da344e0e2d4eca4eadc73afface0f9320f1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / django_case_insensitive_field-1.0.7-py3-none-any.whl

Download URL django_case_insensitive_field-1.0.7-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9415a2ad80168e3f115a8edce0484fa6ee11a58eb3b8d41c282ea61abad80d93
BLAKE2b-256 checksum
How to use checksums
d08fdb3db9b65da0876af3f5fdb659d8d30ceb7eddde4740118c6ccd18c75b7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Security for django-case-insensitive-field 1.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page