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 fo

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

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 multiplyi

Re: why can't I access a dictionary with an initial form field value from my django template?

2011-08-23 Thread Tony Schmidt
Thanks, Reinout. I wound up creating a custom "getter" filter so I could do {{ MYDICT| get:myform.somefiled.value }} - which I'm surprised isn't a built-in, actually. But I think your suggestion is a good alternative. Tony On Aug 23, 1:40 pm, Reinout van Rees wrote: > On 23-08-11 21:16, Tony S

Re: why can't I access a dictionary with an initial form field value from my django template?

2011-08-23 Thread Reinout van Rees
On 23-08-11 21:16, Tony Schmidt wrote: I thought this should be the proper syntax in my template: {{ MYDICT.myform.somefield.value }} But I get a "can't parse remainder error." Just putting {{ myform.somefield.value }} gives me "3" and {{ MYDICT. 3 }} gives me the dictionary value I want. Am

why can't I access a dictionary with an initial form field value from my django template?

2011-08-23 Thread Tony Schmidt
I thought this should be the proper syntax in my template: {{ MYDICT.myform.somefield.value }} But I get a "can't parse remainder error." Just putting {{ myform.somefield.value }} gives me "3" and {{ MYDICT. 3 }} gives me the dictionary value I want. Am I missing something? -- You received th

Re: How set initial form field value in the view function?

2010-07-04 Thread Jim
> The initial keyword is great when defining a subclass of Form if you > the initial values is ALWAYS the same. > > What if it varies?...I'm guessing I must set it in the view. From: http://docs.djangoproject.com/en/1.2/ref/forms/api/#dynamic-initial-values we have: Dynamic initial values¶ F

How set initial form field value in the view function?

2010-07-04 Thread Chris Seberino
How set initial form field value in the view function? The initial keyword is great when defining a subclass of Form if you the initial values is ALWAYS the same. What if it varies?...I'm guessing I must set it in the view. How set this initial value in the view? Chris -- You received

Re: How to set an Admin form field value before displaying the form?

2010-02-11 Thread Nick Booker
The way to do that is to use the 'initial' keyword argument when you instantiate the form, to which you supply a dictionary of field name : initial value e.g.: form = KingModelForm(initial={'first': 'First Name', 'last': 'Surname'}) How you split the name will depend on how you're storing it.

How to set an Admin form field value before displaying the form?

2010-02-11 Thread Derek
I like to set the value/s of a field in a form before displaying it. A rather silly example (to illustrate the principle) : class King(models.Model): name = models.CharField(max_length=250, blank=False) class KingModelForm ( forms.ModelForm ): first = forms.CharField( label = 'Foo', req

Re: Form field value

2007-09-18 Thread Oleg Korsak
this will work only for case if some_field is blank=True,null=True. in any other case it will fail at f.save(commit=False) because of invalid form data (some_field is empty and still required) Nathaniel Whiteinge пишет: > Your best bet is probably to use ``save(commit=False)`` [1]_ to get a > Prof

Re: Form field value

2007-09-08 Thread Nathaniel Whiteinge
Your best bet is probably to use ``save(commit=False)`` [1]_ to get a Profile instance, then set the user fk and call ``save()`` again. This is the example from the newforms docs:: # Create a form instance with POST data. >>> f = AuthorForm(request.POST) # Create, but don't save the

Form field value

2007-09-07 Thread Oleg Korsak
Hello. I have: def save_profile(request): if request.user.is_authenticated(): if request.method == 'POST': try: profile_obj = Profile.objects.get(user__exact=request.user) ProfileForm