1

我正在尝试在我的白板中实现评论功能。该功能允许学生对彼此的图片进行评论。

我有一个应用程序,学生可以在其中创建虚拟白板并在白板内发布与家庭作业相关的图片。

当用户点击查看特定图片下的评论时。该评论确实出现在该特定图片上,但相同的评论出现在它不假设的所有图片上。

我一直在尝试找出一种实现评论功能的方法,这是我唯一的想法。我怎么能解决这个重复问题,因为我一直在想办法把图片和评论联系起来。

看看白板 >

http://imageshack.us/photo/my-images/836/90792660.jpg/

我的 whiteboard.html

 {% if picture %}
 <ul>
    {% for pet in picture %}


        {% if pet.image %}

    <a href ="{% url world:LikePicture pet.id %}"><br>
        <img src= "{{ pet.image.url }}" style="cursor:pointer"></a>
 <br>
    </a>
 </li>
        {% endif %}

 <br>
 <a href="{% url world:CommentCreator pet.id %}">View Comment</a><br/>
      {% for c in comment %}
           <br>{{ c.body }}</li>
           <br>{{ c.created}}</li>
           <br>{{ c.user}}</li>
 {% endfor %}
 {% endfor %}
                </ul>
 {% endif %}

我的观点.py

 def Boat(request ,animal_id):
         if not request.user.is_authenticated():
             return HttpResponseRedirect(reverse('world:LoginRequest'))

    picture = Picture.objects.filter(whiteboard=animal_id)

    return render(request,'whiteboard.html',{'picture':picture})

 def CommentCreator(request,picture_id):
     p = Picture.objects.get(pk=picture_id)
     comment = Comment.objects.filter(picture=p)
     Whiteboard = WhiteBoard.objects.get(whiteboard=p)
     the_id = board.id
     picture = Picture.objects.filter(whiteboard=the_id)

     return render(request,'whiteboard.html',{'picture':picture,'comment':comment})

我的模型.py

 class WhiteBoard(models.Model):

     user = models.ForeignKey(User)
     name = models.CharField(max_length=100)
     picture = models.OneToOneField('Picture',related_name='picture',blank=True,null=True)
     def __unicode__(self):
         return self.name

 class Picture(models.Model):
     user = models.ForeignKey(User)
     Whiteboard = models.ForeignKey(WhiteBoard,blank=False,null=False,related_name='board')
     image = models.FileField(upload_to="images/",blank=True)
     description = models.TextField()
     is_primary = models.BooleanField(default=False)

     def __unicode__(self):
         return self.description
 class Comment(models.Model):
     created = models.DateTimeField(auto_now_add=True)
     user = models.ForeignKey(User)
     body = models.TextField()
     picture = models.ForeignKey(Picture)
4

1 回答 1

0
<a href="{% url world:CommentCreator pet.id %}">View Comment</a><br/>

{% for c in comment %}
    {% ifequal c.picture.id pet.id %}
        <br>{{ c.body }}</li>
        <br>{{ c.created}}</li>
        <br>{{ c.user}}</li>
    {% endifequal %}
{% endfor %}
于 2013-03-22T05:16:07.707 回答