2

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:

Link for the Jquery sample

2
  • I think you should be able to change your selector from $('input.time') to a selector that will match the input rendered by {{ form.as_p }}. It is just rendering an input of type text for that piece of data, which the datepicker will work with. Commented Aug 14, 2012 at 21:29
  • @Gromer: Yeh, you are right, but the problem is How i should use {{form.as_p}} timestamp field with this.timepicker? Commented Aug 14, 2012 at 21:31

3 Answers 3

3

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()
Sign up to request clarification or add additional context in comments.

Comments

2

Unless, I'm gravely misunderstanding you, just use val():

$('#id_timestamp').val($('#time').val())

2 Comments

Thanks for the replying @Chris but How should i integrate it with Django Forms. I mean it *** {{ form.as_p }} ***. And you can see the Django Form class. So how should i use it? I am not the best in Django. Would you please update the code according to it.
That sets the value of the timestamp field to the value of the other field. Django just processes the form as normal. Not sure what more you're looking for.
2

Does this not work:

<input class="time" type="text" name="start" id="start" value="{{form.timestamp}}" />

Sorry, I'm not an expert in Django.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.