python - Django input as hour and minutes, saved as minutes -
in django webapp, i'm creating form user inputs time taken complete activity in hours , minutes (eg. 2 hours, 33 minutes).
i want input appear client side hours , minutes, save model minutes (eg. 153)
currently, input given in minutes. worry ugly/unreadable:
models.py:
class activity(models.model): time_taken = models.positiveintegerfield(default=0)
add_activity.html:
<form id="add_session_form" method="post" action="" enctype="multipart/form-data"> {% csrf_token %} {{ add_activity_form.as_p }} <input type="submit" name="submit" value="add activity" /> </form>
forms.py:
class activity(forms.modelform): class meta: model = activity fields = ('time_taken', 'subject')
could please assist me in altering form's input users individually enter hours , minutes, whilst storing time in minutes.
in form
class activityform(forms.modelform): hours = forms.integerfield(max_value=12,min_value=0) class meta: model = activity fields = ('time_taken', 'subject')
render forms doing
in view
form = activityform(request.post) hours = form.cleaned_data['hours'] minutes = form.cleaned_data['time_taken'] total_time = 60*hours + minutes activity.objects.create(time_taken = total_time)
Comments
Post a Comment