>
> If you want that behavior, just truncate `myfield` in `MyModel.save()`
> before calling the super save.
>
> <http://docs.djangoproject.com/en/dev/ref/models/instances/#django.db....>
Well, if that's THE solution, then I'll post my implementation - maybe
someone will find it useful:
def autotruncate(cls):
oldsave = cls.save
def newsave(self, **kwargs):
for f in self._meta._fields():
if isinstance(f, models.CharField):
val = getattr(self, f.name)
if val is not None:
setattr(self, f.name, val[:f.max_length])
oldsave(self, **kwargs)
cls.save = newsave
To use it, write:
autotruncate(MyModel)
Any comments are welcome.
Regards,
MS
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---