KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
We implemented a LowerCaseCharField. We would be happy to hear better implementation suggestions. from django.db.models.fields import CharField class LowerCaseCharField(CharField): """ Defines a charfield which automatically converts all inputs to lowercase and saves. """ def pre_save(self, model_instance, add): """ Converts the string to lowercase before saving. """ current_value = getattr(model_instance, self.attname) setattr(model_instance, self.attname, current_value.lower()) return getattr(model_instance, self.attname) In fact we love to have is: > modelinstance.field_name="TEST" > print modelinstance.field_name 'test' current implementation only converts to lowercase when it is saved.
Tags (comma-separated)
Save Edits
Cancel