Arkaitz Jimenez
Arkaitz Jimenez

Reputation: 23178

How to validate 'instance' in a Django form constructor MyForm(instance=myInstance)

I have the data stored in a format different from the display format.
I've already worked out the form-to-db conversion in the clean_weight() method of the form, this gives me access to properly format data before saving it.

Now I pretend to manipulate the instances weight before the form is displayed but I fail to see a good place to do this inside the form code.

I have 2 alternatives that I know:

For the moment of those 2 the one that looks better is the constructor one, but stinks to me.
Any hint?

Upvotes: 0

Views: 335

Answers (1)

Dmitry Shevchenko
Dmitry Shevchenko

Reputation: 32404

Custom form field is what you need - simple, clean, reusable on any form. Probably even custom model field, but that is up to you.

Upvotes: 1

Related Questions