I have an author who doesn't understand that a space is not nothing. He persists in *sometimes* putting a leading space at the beginning of a 'name' field. This name shows up in a ForeignKey drop down in the admin interface. As a result, we often end up with two records. He creates one named " Foo" (note the leading space). When he goes to the dropdown he doesn't see it because it is first in the sort order (not where he would expect it to be) and so he creates another record with the name "Foo" (i.e., without the space). He will then sometimes use the " Foo" record and sometimes the "Foo" record and things get screwed up.
I would love to have a CharField option, strip=True, that strips leading/trailing spaces. I don't want to edit core, and I don't want to monkey patch. So that leaves me with either a) create a save() for each model that has one of these fields, or b) have a Field type that does it for me. I have a number of these, so I opted for the later. E.g., class CharFieldStripped(models.CharField): def get_db_prep_save(self, value): if value is not None: value = value.strip() return super(models.CharField, self).get_db_prep_save(value) So, is this the "best" way to do this? Is there a more general/correct mechanism for adding options to Fields? Enquiring minds want to know! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---