I have a follwoing Jquery code, which create a Time Picker
:
<input class="time" type="text" name="start" id="start" />
$('input.time').timepicker();
And i want to use this time picker value which comes into the text in Django-Forms.
My models.py
:
class UsertTime(models.Model):
user = models.ForeignKey(User, blank=False)
data = models.CharField(max_length=30)
timestamp = models.DateTimeField(blank=True, null=True)
my forms.py
:
class UserTimeForm(forms.ModelForm):
class Meta:
model = UserTime
In my template.html
:
<form action="" method="POST">
{{ form.as_p }}
<input type="submit" value="{% trans "Add " %}" /> <a href="{% url host_list %}">{% trans "Cancel" %}</a>
</form>
<input class="time" type="text" name="start" id="start" />
$('input.time').timepicker();
Now how should i fill the timestamp
Field by the Jquery
written input. Following is the refer link for the Jquery Code:
I might also be misunderstanding; but, can you not just inspect the output of form.as_p
and operate on that input instead of $('input.time')
$('#id_timestamp').timepicker()
Does this not work:
<input class="time" type="text" name="start" id="start" value="{{form.timestamp}}" />
Sorry, I'm not an expert in Django.
除非,我对您有严重的误解,请使用val()
:
$('#id_timestamp').val($('#time').val())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.