0
我創建的博客,文章只發布login.so有四個表,如用戶,JSdetails,博客,評論。這四張表格是相互關聯的。這裏我想在評論中顯示個人資料圖片。我曾試過,但無法顯示。給我一些想法。我加了模型,視圖模板下面...從關係表Django濾波器查詢
models.py
class User(models.Model):
first_name=models.CharField()
last_name=models.CharField()
username=models.CharField()
class JSdetails(models.Model):
user=models.ForeignKey(User)
profilepic=models.ImageField(upload_to='Image')
class Blog(models.Model):
user=models.ForeignKey(User)
btitle=models.CharField()
bcontent=models.TextField(blank=True)
bposted=models.DateTimeField(auto_now = True)
class BComments(models.Model):
user=models.ForeignKey(User)
blog=models.ForeignKey(Blog)
comments=models.TextField()
commentpost=models.DateTimeField(auto_now = True)
views.py
def blogArticle(request):
articleid=1
article=Blog.objects.filter(id=articleid)
com=BComments.objects.filter(blog_id=articleid)
return render_to_response('registration/BlogArticle.html',{'article':article,'com':com},context_instance=RequestContext(request))
模板
/* Here Article will display */
{% for article in article %}
<h2>{{article.btitle}}</h2>
<p style="text-align:justify;">{{article.bcontent}}</p>
{% endfor %}
/* Here Comments get displayed which is posted by user */
{% for com in com %}
<img style="width:50px;height:50px;" src="Here I need to Display Profile picture" >
<span>{{com.user.username}}</span>
<p style="word-wrap:break-word;">
{{com.comments}}
</p>
{% endfor %}
你不使用JSdetails任何地方 – rjv