本文整理汇总了Python中models.Comment.owner方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.owner方法的具体用法?Python Comment.owner怎么用?Python Comment.owner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.owner方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sp
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import owner [as 别名]
def sp(request, id='1'):
if request.method == "POST":
text = request.POST['text']
user = User.objects.get(username=request.user)
nn = get_object_or_404(News, id=id)
nc = Comment()
nc.owner = user
nc.text = text
nc.news = nn
nc.save()
return redirect(request.path)
from_date = datetime.datetime.now() - datetime.timedelta(days=2)
l2dn = News.objects.all().order_by('-date').filter(date__range=[from_date, datetime.datetime.now()])
ln = News.objects.all()[:5]
ct = City.objects.all()
n = get_object_or_404(News, id=id)
c = Categoryitem.objects.select_related().filter(parent=None)
com = Comment.objects.select_related().filter(news=n, parent=None)
context = {'news': n,
'cats': c,
'citys': ct,
'comments': com,
'lnews': ln,
'last_news': l2dn}
return render(request, 'news/sp.html', context)
示例2: addcomment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import owner [as 别名]
def addcomment(request):
if request.method == "POST":
news = News.objects.get(id=request.POST['news'])
text = request.POST['text']
user = User.objects.get(username=request.user)
c = Comment()
c.news = news
c.owner = user
c.text = text
if request.POST['pid'] != 'false':
pid = request.POST['pid']
c.parent = Comment.objects.get(id=pid)
c.save()
return HttpResponse(c.id)