Sunday, April 1, 2012

Re: Preprocess data before showing it on Admin

On Sun, Apr 1, 2012 at 9:42 PM, Pedro Vasconcelos <pedro@pedrorafa.com> wrote:
> Hello Marc!
>
> Thanks for replying. Unfortunately I cant realised how to get the current
> value, change it and populate the form using a ModelForm. I've tried it
> actually.
>
sure, you can do it on form __init__ method

something like

class YourForm(ModelForm):
def __init__(self, *args, **kwargs):
super(YourForm, self).__init__(*args, **kwargs)
self.fields['your_field'].initial = your_postprocess_method()

also you should override the save form method in order to "reverse"
the postprocess and save the data in raw format.


--
Marc

--
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