1

There doesn't seem to exist a case independent model.CharField() in Django? That makes case independent unique values and list look-ups somewhat difficult.

For example, I am trying to do a Model.objects.filter(field__in=[large-str-list]) lookup, with all the str values being randomly uppercase and lowercase. There is a 5-year-old answer here.

Also, ensuring case independent unique-ness of a model.CharField() can't be done by Django. There is another 5-year-old answer here for that.

I was wondering if there is already a better solution now, maybe in the form of a model.ICharField() that can take care of off these things.

Community
  • 1
  • 1
C14L
  • 12,153
  • 4
  • 39
  • 52
  • is it possible to save and query only values casted to `.lower()`? – sobolevn Dec 01 '15 at 15:17
  • http://stackoverflow.com/questions/9486811/case-insensitive-charfield-in-django-models This might answer your second question. – Shang Wang Dec 01 '15 at 15:30
  • the case stored in the database is part of the data and must be kept. A workaround would be to add a second "lookup" field and lowercase that. But I was hoping for a way without any such hacks... – C14L Dec 01 '15 at 15:31

1 Answers1

0

Maybe you could try to create your own field. It should not be too hard to check for uniqueness during insertions. As far as I know there is not a native Django solution for that. The old links in your post might help you.

Raphaël Gomès
  • 938
  • 1
  • 8
  • 23