Noob question (forms)
Closed this issue · 4 comments
xsanch commented
Hi,
i am trying to extend your demo with another field in the form but unfortunately I am not getting anything to Django:
<form class="form-inline ajax" method="post" action="{% url task_add %}" data-append="#tasks">
{% csrf_token %}
<div class="input-append">
<input type="text" class="span4" name="label" placeholder="Enter a stream name...">
</div>
<div class="input-append">
<input type="text" class="span4" name="phonenumber" placeholder="Enter a phonenumber...">
</div>
</form>
Added the phonenumber field:
views.py:
@require_POST
def add(request):
session = Session.objects.get(session_key=request.session.session_key)
if Task.objects.filter(label__exact=request.POST.get("label")).exists():
data = _task_data(request,Task.objects.get(label__exact=request.POST.get("label")),True)
return HttpResponse(json.dumps(data), mimetype="application/json")
task = Task.objects.create(
session=session,
label=request.POST.get("label"),
phonenumber=request.POST.get("phonenumber")
)
data = _task_data(request, task)
return HttpResponse(json.dumps(data), mimetype="application/json")
models.py:
class Task(models.Model):
session = models.ForeignKey(Session)
label = models.CharField(max_length=100)
done = models.BooleanField(default=False)
phonenumber = models.CharField(max_length=10)
I am sorry but I am really new to django / ajax.
NamPNQ commented
You can check in function _task_data(request,task)
paltman commented
@xsanch i am not really following your question or what you are wanting to accomplish. Can you elaborate?