0

I use JQuery Datepicker and cannot get data from it. In .html:

<p>Date: <input type="text" id="datepicker"/>&nbsp;</p>

In models.py:

class RecordModel(models.Model):
    ...
    Date = models.DateField(blank = False)
    ...

In forms.py:

class RecordForm(forms.ModelForm):
    ...
    #There is no Date field
    ...

In views.py:

def doc(request, DocName):
    S = request.POST.get("Date") # error

Value of S in doc() function in views.py is "" (empty string), even if I choose date in a widget. How to get real data?

3
  • 1
    Is the first snippet (HTML) a custom code or generated by Django forms? I guess it's the former, in which case the value of this field can't be found in request.POST because the input doesn't have name attribute specified. I'd suggest attaching the Datepicker to the DateField (or is the problem here that Date field of the ModelForm is not being rendered?). Commented Feb 3, 2012 at 6:28
  • "Is the first snippet (HTML) a custom code" - yes. Thank you for the solution. "I'd suggest attaching the Datepicker to the DateField" - how to do it? Commented Feb 3, 2012 at 6:41
  • 1
    Is the Date field (from RecordForm) displayed? If so, the jQuery part in this case would be something like $( "#id_Date" ).datepicker();. Commented Feb 3, 2012 at 6:47

1 Answer 1

1

You need a name attribute to submit data.

You are looking for a POST data keyed by Date but I don't see a name=Date anywhere.

It should be:

<input type="text" id="datepicker" name="Date"/>&nbsp;</p>
Sign up to request clarification or add additional context in comments.

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.