Saturday, October 30, 2010

Re: overriding save-method

Write a custom model field:
http://docs.djangoproject.com/en/dev/howto/custom-model-fields/

Or even better, take already written one:
http://djangosnippets.org/snippets/377/

On Oct 27, 9:14 am, Patrick <ptrckdn...@googlemail.com> wrote:
> hi,
>
> i am trying to override the save-method of one of my models. i want to
> save the json-representation of any object in a text field. somehow it
> doesn't seem to work.
>
> class Setting(models.Model):
>     name = models.CharField(max_length=100)
>     value = models.TextField()
>
>     def save(self, *args, **kwargs):
>         self.value = json.dumps(self.value)
>         super(Setting, self).save(*args, **kwargs)
>
> any ideas?! thank you..

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment