Re: Add poll to the django tutorial polls

2014-04-06 Thread Camilo Torres
On Saturday, April 5, 2014 8:13:04 AM UTC-4:30, Christo bale wrote:
>
> I would like to make it possible to add a poll on the index.html, so one 
> don't need the admin. 
> I added a forms.py.
> Right now when I click enter after typing the new poll, the sites goes 
> blank and I need to refresh it. And no polls have been added. I am pretty 
> new to django, so I hope that you can help me.  
>
> forms.py
> class ComposePoll(forms.ModelForm):
> class Meta:
> fieldsets = [
> (None,   {'fields': ['question']}),
> ('Date information', {'fields': ['pub_date'], 'classes': 
> ['collapse']}), 
> ]
>
> index.html
>
>  {% csrf_token %}
> {{ form.add_poll }}
> 
> 
>
> views.py
> class IndexView(generic.ListView):
> template_name = 'polls/index.html'
> context_object_name = 'latest_poll_list'
>
> def get_queryset(self):
> """
> Return the last five published polls (not including those set to be
> published in the future).
> """
> return Poll.objects.filter(
> pub_date__lte=timezone.now()
> ).order_by('-pub_date')[:5]
> 
> add_poll = ComposePoll(request.POST or None)
> if add_poll.is_valid():
> create_poll = Poll.save(commit=False)
> create_poll.sent = datetime.datetime.now()
> create_poll.save()
> return HttpResponseRedirect('/polls/')
> 
> poll = Poll.objects.filter()
> 
> return render_to_response('polls/index.html', locals(), 
> context_instance=RequestContext(request))
>
Hello,

You should add a 'post' method to your view to get the data from the form 
and store it in your models.

Regards,

Camilo.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4ce00fee-daf9-498e-b502-46c68b62f95d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Add poll to the django tutorial polls

2014-04-05 Thread Christo bale
I would like to make it possible to add a poll on the index.html, so one 
don't need the admin. 
I added a forms.py.
Right now when I click enter after typing the new poll, the sites goes 
blank and I need to refresh it. And no polls have been added. I am pretty 
new to django, so I hope that you can help me.  

forms.py
class ComposePoll(forms.ModelForm):
class Meta:
fieldsets = [
(None,   {'fields': ['question']}),
('Date information', {'fields': ['pub_date'], 'classes': 
['collapse']}), 
]

index.html

 {% csrf_token %}
{{ form.add_poll }}



views.py
class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_poll_list'

def get_queryset(self):
"""
Return the last five published polls (not including those set to be
published in the future).
"""
return Poll.objects.filter(
pub_date__lte=timezone.now()
).order_by('-pub_date')[:5]

add_poll = ComposePoll(request.POST or None)
if add_poll.is_valid():
create_poll = Poll.save(commit=False)
create_poll.sent = datetime.datetime.now()
create_poll.save()
return HttpResponseRedirect('/polls/')

poll = Poll.objects.filter()

return render_to_response('polls/index.html', locals(), 
context_instance=RequestContext(request))

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7d707534-c5e1-420d-9727-7beff47a0ee8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.