Currently, I have a Django project containing a model called Event
which has several properties, one of them being full_name
.
from django.db import models
class Event(models.Model):
description = models.CharField(blank=False, max_length=200)
full_name = models.CharField(blank=False, null=True, max_length=200, unique=True)
What I want to acchieve is to prevent users from making two events in which one would be called MyEvent
and the other would be called myevent
, so I want the name to not be case sensitive. Furthermore, I come from a country with some funny letters, like š
. Users are so used to computer systems not supporting these letters that I want to also prevent the existance of two events, one called šoo
and the other soo
.
Basically, I have a function myfunction
and want to have a model constraint such that for each instance of the model, the value myfunction(instance.full_name)
is unique.
My first idea, which sort of works, is to have a model form with a clean full name function:
def clean_full_name(self):
return myfunction(self.cleaned_data.get('full_name'))
This works. However, I now have a view in which I want to display the full names of all events, and here, I want to display the original names. Using my approach, this is impossible (the funcion is one-way only). Is there an elegant solution to this?