Hey everyone! I have a model field that returns an object of type Quantity(). It’s based on Pint for measurements. It’s a custom object that contains a magnitude (i.e. 5) and a unit (i.e. gallons).
I’m looking for a way to modify/format this data when being displayed in both Forms and HTML pages. I was looking at doing a custom tag, but that doesn’t help with forms. So, I figured a custom widget would work.
Is there a way I can keep the custom object in my models and DB, but when displayed, get’s a special format without duplicating (i.e. Tag AND Widget)?
You really are talking about two different renderings here. One would be represented by an <input element, the other being the textual content of a field value.
(* I should clarify - Yes, you could do it by creating a custom template that checks to see if it’s being used in a form or as text, using that template as the form field and as the target of a custom tag, with some type of indicator showing which one is to be used. However, you would have a hard time convincing me that there’s any real value in the effort involved in doing it. My opinion is that that solution is a lot worse than just dealing with two different renderings.)