So I have the standard django tutorial polls app and I made a little blog app. Is there a simple way to add a poll to some of the blog posts but not all.
I’ve found this:
from django.models.polls import polls
from django.models.blogs import posts
def my_view(request):
return render_to_response("template_name", {
"poll_list" : polls.get_list(),
"post_list" : posts.get_list(),
}
But how do I pick which poll I want in the template and if I add it to the template won’t it show up in every post? I feel like im seriously over-thinking or under-thinking this. Any advice or links would be appreciated. Thanks.
models.py #for the blog app
class Post(models.Model):
title = models.CharField(max_length=60)
description = models.TextField()
body = models.TextField()
created = models.DateTimeField(auto_now_add=True)
def display_mySafeField(self):
return mark_safe(self.body)
def __unicode__(self):
return self.title
views.py # for blog class
def post(request, pk):
"""Single post with comments and a comment form."""
post = Post.objects.get(pk=int (pk))
comments = Comment.objects.filter(post=post)
d = dict(post=post, comments=comments, form=CommentForm(), user=request.user,
months=mkmonth_lst())
d.update(csrf(request))
return render_to_response("post.html", d)
I want to add a poll to a post but not all of them.
Add something which will indicate which poll is associated to which model. You can use
ForeignKey,ManyToManyField,GenericForeignKey,OneToOneField, etc and then use that indicator to get poll/s associated to post/s .