1
1
1998or22021-04-12 14:03:10
Django
1998or2, 2021-04-12 14:03:10

How to be case insensitive in Django models?

Can you tell me how to make the django model so that it is case insensitive?
For example:

Tag = models.CharField(max_length=15, verbose_name='Тег', unique=True)
Category = models.ForeignKey(Post, max_length=15, verbose_name='Категррия', Unique=True)


The fields are filled from the admin panel. When I enter, for example, the category Phones, then the second time you cannot enter Phones due to Unique=True, but you can enter phones with a small letter, and then the category will still be duplicated, which is not very desirable.
It seems like a trifle, but I can not figure out how to do it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2021-04-12
@1998or2

You can use citext-fields

from django.db import models
from django.contrib.postgres.fields import CITextField

class YourModel(models.Model):
    Tag = CITextField()

Naturally only works with postgresql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question