Guys, i'm struggling with this problem for more than a week now. My
goal is to use a queryset filter with a foreign key.
Issues are
1) column generates a list, what is the right way to get the blog id
for a post? So whether the post belongs to blog 1 question or blog 2
answer? Tried Post.objects.get which fails...
2) howto define this in the template
Any help/ directions are appreciated!
********** First I created this model with a foreign key
**************************
class blog(models.Model):
function_CHOICES = (
(1, _('question')),
(2, _('answer')),
)
function = models.IntegerField(_('function'),
choices=function_CHOICES, default=2)
def __unicode__(self):
return self.get_function_display()
class Post(models.Model):
blog = models.ForeignKey(blog)
********* This is the view with the 'column definition'
**********************
def blogs(request, username=None, template_name="blog/blogs.html"):
blogs = Post.objects.filter(status=2).select_related
(depth=1).order_by("-publish")
column = Post.objects.values(blog__id).select_related('blog')
if column == 1:
blogs = blogs.filter(author=user).exclude(column==2)
pass
blogs = blogs.filter(author=user).exclude(column==1)
return render_to_response(template_name, {
"blogs": blogs,
}, context_instance=RequestContext(request))
********* Template. Goal: create 2 columns filtered by whether column
=1 or 2 ************
<table>
<tr>
<td>
{% if blogs %}
<p>{% trans "These are blog posts from everyone:" %}</p>
{% autopaginate blogs %}
********** if column == 1 **********
{% for blog_post in blogs %}
{% show_blog_post blog_post %}
{% endfor %}
{% paginate %}
{% else %}
{% trans "No blog posts yet." %}
{% endif %}
</td>
<td>
{% if blogs %}
<p>{% trans "These are blog posts from everyone:" %}</p>
********** condition for passed data
**********
{% autopaginate blogs %}
{% for blog_post in blogs %}
{% show_blog_post blog_post %}
{% endfor %}
{% paginate %}
{% else %}
{% trans "No blog posts yet." %}
{% endif %}
</td>
</tr>
</table>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.