示例#1
0
def index(request):
    teddys = Teddy.objects.all()
    posts = Post.objects.all()
    template = loader.get_template('index.html')

    return HttpResponse(template.render(RequestContext(request, {
        'teddys': teddys,
        'posts': posts,
        'username': utils.get_username_or_fullname(request.user)
    })))
示例#2
0
def post_comments_as_json(request, teddy_id, post_id):
    post = get_object_or_404(Post, pk=post_id)
    comments = []
    for comment in post.comment_set.all().order_by("-comment_time"):
        comments.append([comment.comment,
                         utils.get_username_or_fullname(comment.user),
                         comment.user.id,
                         utils.get_friendly_time(comment.comment_time)])
    comments = post.comment_set.all().order_by("-comment_time")
    comment_dictionary = [{
                          'comment': c.comment,
                          'comment_time': utils.get_friendly_time(c.comment_time),
                          'user_id': c.user.id,
                          'user_name': c.user.username,

                          } for c in comments]
    data = json.dumps(comment_dictionary)
    return HttpResponse(data, mimetype='application/json')