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
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
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
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
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
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
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
> 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?
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
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.
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
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
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
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
14 matches
Mail list logo