Re: Unit conversions between model field value and form field value

2019-05-08 Thread Jani Tiainen
Hi. You could create custom form field that makes conversions both ways. ke 8. toukok. 2019 klo 1.25 Tim Bell kirjoitti: > Hi, > > I have a model with an integer field storing a duration in hours, while I > want to present that to users in a form in days. (The choice of these > different units

Re: Unit conversions between model field value and form field value

2019-05-07 Thread Shashank Singh
One way could be make a custom read only field to show it in current value in days and take a custom field and on save_model take its value as days multiply it with 24 and save it in model's field. On Wed, May 8, 2019, 7:05 AM Joe Reitman wrote: > Hi Tim, > > There is a 'Best Practices' guide

Re: Unit conversions between model field value and form field value

2019-05-07 Thread Joe Reitman
Hi Tim, There is a 'Best Practices' guide for Django that recommends making models fat, https://django-best-practices.readthedocs.io/en/latest/applications.html#models. With that it would be logical to do both conversions in the model. Regards, Joe On Tuesday, May 7, 2019 at 5:24:09 PM

Unit conversions between model field value and form field value

2019-05-07 Thread Tim Bell
Hi, I have a model with an integer field storing a duration in hours, while I want to present that to users in a form in days. (The choice of these different units is imposed by other factors not under my control.) So, when saving a form, I need to convert a value in days to hours by