本文整理汇总了Python中django.contrib.comments.models.Comment.add_to_class方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.add_to_class方法的具体用法?Python Comment.add_to_class怎么用?Python Comment.add_to_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.comments.models.Comment
的用法示例。
在下文中一共展示了Comment.add_to_class方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getattr
# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import add_to_class [as 别名]
to count these vs doing a count db call
"""
comments = []
for comment in self.get_query_set():
if getattr(settings, 'COMMENTS_HIDE_REMOVED', True):
if not comment.is_removed and comment.is_public:
comments.append(comment)
elif comment.is_public:
comments.append(comment)
return len(comments)
# add additional fields onto the comment model
Comment.add_to_class('uuid', UUIDField())
Comment.add_to_class('created', models.DateTimeField(auto_now_add=True, editable = False, blank = True, null = True))
Comment.add_to_class('modified', models.DateTimeField(auto_now=True, blank = True, null = True))
Comment.add_to_class('parent', models.ForeignKey('self', related_name = 'children', blank = True, null = True))
Comment.add_to_class('type', models.CharField(max_length = 255, blank = True, null = True))
Comment.add_to_class('data', PickleField(blank = True, null = True))
# additional methods
Comment.add_to_class('template', get_comment_template)
Comment.add_to_class('get_css_class', get_css_class)
Comment.add_to_class('set_comment_template_dir', set_comment_template_dir)
Comment.add_to_class('get_reply_form', get_reply_form)
Comment.add_to_class('_default_manager', PrimerCommentManager())
示例2: CommentManager
# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import add_to_class [as 别名]
from openPLM.plmapp.models.plmobject import *
from openPLM.plmapp.models.part import *
from openPLM.plmapp.models.document import *
from openPLM.plmapp.models.history import *
from openPLM.plmapp.models.link import *
# monkey patch Comment models to select related fields
from django.contrib.comments.models import Comment
from django.contrib.comments.managers import CommentManager
class CommentManager(CommentManager):
def get_query_set(self):
return (super(CommentManager, self)
.get_query_set()
.select_related('user', 'user__profile'))
Comment.add_to_class('objects', CommentManager())
# import_models should be the last function
def import_models(force_reload=False):
u"""
Imports recursively all modules in directory *plmapp/customized_models*
"""
MODELS_DIR = "customized_models"
IMPORT_ROOT = "openPLM.plmapp.%s" % MODELS_DIR
if __name__ != "openPLM.plmapp.models":
# this avoids to import models twice
return
if force_reload or not hasattr(import_models, "done"):
import_models.done = True
示例3: likes_anonymous
# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import add_to_class [as 别名]
def likes_anonymous(self):
return len(Like.objects.get_likes_anonymous(self))
tagging.register(Post)
# TODO: update post last modified date upon new like signal (and remove from views.add_like)
# TODO: add 'via_service' foreign key
class Like(Tracked, OwnableSometimes, GenericObject):
"""
User and anonymous likes for objects
"""
objects = LikeManager()
@property
def get_comment_likes(self):
return Like.objects.get_likes(self)
Comment.add_to_class('likes', get_comment_likes)
@property
def get_comment_likes_users(self):
return [like.user for like in Like.objects.get_likes_users(self)]
Comment.add_to_class('likes_users', get_comment_likes_users)
from .signals import *