Model for uppercase CharField ?

3,058 views
Skip to first unread message

du...@habmalnefrage.de

unread,
Jul 23, 2006, 4:52:45 AM7/23/06
to django...@googlegroups.com
Hi all,

I had the need for a CharField which stores the values always in uppercase form. Is there a solution out there ?

Maybe the follwing simple generic solution would be fine:

class UpperCase(models.Model):
uppercase_field = models.CharField(maxlenght=10, uppercase=True)

Regards,
Dirk
--


Echte DSL-Flatrate dauerhaft für 0,- Euro*. Nur noch kurze Zeit!
"Feel free" mit GMX DSL: http://www.gmx.net/de/go/dsl

Ivan Sagalaev

unread,
Jul 23, 2006, 5:04:16 AM7/23/06
to django...@googlegroups.com
du...@habmalnefrage.de wrote:
> Hi all,
>
> I had the need for a CharField which stores the values always in uppercase form. Is there a solution out there ?
>
> Maybe the follwing simple generic solution would be fine:
>
> class UpperCase(models.Model):
> uppercase_field = models.CharField(maxlenght=10, uppercase=True)

For now you can override "save" method of the model:

def save(self):
self.uppercase_field = self.uppercase_field.upper()
super(MyModel, self).save()

James Bennett

unread,
Jul 23, 2006, 1:29:59 PM7/23/06
to django...@googlegroups.com
On 7/23/06, du...@habmalnefrage.de <du...@habmalnefrage.de> wrote:
> I had the need for a CharField which stores the values always in uppercase form. Is there a solution out there ?

Ivan's suggestino of adding a custom save() method on the model which
uppercases the contents of the field you want uppercased is probably
your best bet; trying to add model fields and options for every type
of constraint people might want would unnecessarily complicate the
model system, especially when we've already got ways to handle that
sort of thing.

--
"May the forces of evil become confused on the way to your house."
-- George Carlin

Reply all
Reply to author
Forward
0 new messages