def get_entry_model(): """ Return the actual entry model that is in use. This function reads the :ref:`FLUENT_BLOGS_ENTRY_MODEL` setting to find the model. The model is automatically registered with *django-fluent-comments* and *django-any-urlfield* when it's installed. """ global _EntryModel if _EntryModel is None: # This method is likely called the first time when the admin initializes, the sitemaps module is imported, or BaseBlogMixin is used. # Either way, it needs to happen after all apps have initialized, to make sure the model can be imported. if not appsettings.FLUENT_BLOGS_ENTRY_MODEL: _EntryModel = Entry else: app_label, model_name = appsettings.FLUENT_BLOGS_ENTRY_MODEL.rsplit('.', 1) _EntryModel = get_model(app_label, model_name) # Auto-register with django-fluent-comments moderation if 'fluent_comments' in settings.INSTALLED_APPS and issubclass(_EntryModel, CommentsEntryMixin): from fluent_comments.moderation import moderate_model moderate_model(_EntryModel, publication_date_field='publication_date', enable_comments_field='enable_comments', ) # Auto-register with django-any-urlfield if 'any_urlfield' in settings.INSTALLED_APPS: from any_urlfield.models import AnyUrlField from any_urlfield.forms.widgets import SimpleRawIdWidget AnyUrlField.register_model(_EntryModel, widget=SimpleRawIdWidget(_EntryModel)) return _EntryModel
def get_entry_model(): """ Return the actual entry model that is in use. This function reads the :ref:`FLUENT_BLOGS_ENTRY_MODEL` setting to find the model. The model is automatically registered with *django-fluent-comments* and *django-any-urlfield* when it's installed. """ global _EntryModel if _EntryModel is None: # This method is likely called the first time when the admin initializes, the sitemaps module is imported, or BaseBlogMixin is used. # Either way, it needs to happen after all apps have initialized, to make sure the model can be imported. if not appsettings.FLUENT_BLOGS_ENTRY_MODEL: _EntryModel = Entry else: app_label, model_name = appsettings.FLUENT_BLOGS_ENTRY_MODEL.rsplit( '.', 1) if django.VERSION < (1, 7): _EntryModel = get_model(app_label, model_name, only_installed=False) else: _EntryModel = get_model(app_label, model_name) if _EntryModel is None: raise ImportError( "{app_label}.{model_name} could not be imported.".format( app_label=app_label, model_name=model_name)) # Auto-register with django-fluent-comments moderation if 'fluent_comments' in settings.INSTALLED_APPS and issubclass( _EntryModel, CommentsEntryMixin): from fluent_comments.moderation import moderate_model moderate_model( _EntryModel, publication_date_field='publication_date', enable_comments_field='enable_comments', ) # Auto-register with django-any-urlfield if 'any_urlfield' in settings.INSTALLED_APPS: from any_urlfield.models import AnyUrlField from any_urlfield.forms.widgets import SimpleRawIdWidget AnyUrlField.register_model(_EntryModel, widget=SimpleRawIdWidget(_EntryModel)) return _EntryModel
content = models.TextField("Content") publication_date = models.DateTimeField("Publication date") enable_comments = models.BooleanField("Enable comments", default=True) # Optional reverse relation, allow ORM querying: comments_set = CommentsRelation() class Meta: verbose_name = "Article" verbose_name_plural = "Articles" def __unicode__(self): return self.title def get_absolute_url(self): return reverse('article-details', kwargs={'slug': self.slug}) # Optional, give direct access to moderation info via the model: comments = property(get_comments_for_model) comments_are_open = property(comments_are_open) comments_are_moderated = property(comments_are_moderated) # Give the generic app support for moderation by django-fluent-comments: moderate_model( Article, publication_date_field='publication_date', enable_comments_field='enable_comments' )
blank=True, null=True) tags = models.ManyToManyField(Tag) def __str__(self): return self.post_title def was_published_recently(self): return self.pub_date >= timezone.now() - datetime.timedelta(days=1) def save(self, *args, **kwargs): if not self.id: self.post_slug = slugify(self.post_title) super(Post, self).save(*args, **kwargs) def get_absolute_url(self): return reverse('detail', kwargs={ 'post_slug': self.post_slug, }) def get_text_batch(self): return self.post_text[:250] + "..." moderate_model( Post, publication_date_field='publication_date', enable_comments_field='enable_comments', )
class Article(models.Model): comments_set = CommentsRelation() """ def __init__(self, *args, **kwargs): super(CommentsRelation, self).__init__( to=get_comments_model(), content_type_field='content_type', object_id_field='object_pk', **kwargs ) try: from south.modelsinspector import add_ignored_fields except ImportError: pass else: # South 0.7.x ignores GenericRelation fields but doesn't ignore subclasses. # Taking the same fix as applied in http://south.aeracode.org/ticket/414 _name_re = "^" + __name__.replace(".", "\.") add_ignored_fields(( _name_re + "\.CommentsRelation", )) moderate_model( Comment, publication_date_field='date', enable_comments_field='enable_comments' )
class CommentsRelation(GenericRelation): """ A :class:`~django.contrib.contenttypes.generic.GenericRelation` which can be applied to a parent model that is expected to have comments. For example: .. code-block:: python class Article(models.Model): comments_set = CommentsRelation() """ def __init__(self, *args, **kwargs): super(CommentsRelation, self).__init__(to=get_comments_model(), content_type_field='content_type', object_id_field='object_pk', **kwargs) try: from south.modelsinspector import add_ignored_fields except ImportError: pass else: # South 0.7.x ignores GenericRelation fields but doesn't ignore subclasses. # Taking the same fix as applied in http://south.aeracode.org/ticket/414 _name_re = "^" + __name__.replace(".", "\.") add_ignored_fields((_name_re + "\.CommentsRelation", )) moderate_model(Comment, publication_date_field='date', enable_comments_field='enable_comments')
comments_set = CommentsRelation() class Meta: verbose_name = "Article" verbose_name_plural = "Articles" def __str__(self): return self.titre comments = property(get_comments_for_model) comments_are_open = property(comments_are_open) comments_are_moderated = property(comments_are_moderated) def get_absolute_url(self): return reverse('blog:detailArticle', kwargs={'pk': self.id}) moderate_model( Article, publication_date_field='date', enable_comments_field='statut' ) class Commentaire(models.Model): auteur = models.ForeignKey(User, on_delete = models.CASCADE) article = models.ForeignKey(Article, on_delete = models.CASCADE) contenu = models.CharField(max_length = 150) date = models.DateTimeField(auto_now_add= True) def __str__(self): return self.contenu
verbose_name = '新闻' verbose_name_plural = '新闻' ordering = ['-pub_date'] def __unicode__(self): return self.title def save(self, force_insert=False, force_update=False): self.body_html = markdown(self.body) if self.excerpt: self.excerpt_html = markdown(self.excerpt) super(News, self).save(force_insert, force_update) def get_absolute_url(self): return ('zenews_news_detail', (), {'year': self.pub_date.strftime("%Y"), 'month': self.pub_date.strftime("%m"), 'day': self.pub_date.strftime("%d"), 'slug': self.slug}) get_absolute_url = models.permalink(get_absolute_url) # The comment moderate with akismet. from fluent_comments.moderation import moderate_model from zenews.models import News moderate_model(News, publication_date_field='pub_date', enable_comments_field='enable_comments', )
FormSubmissionsPanel(), FieldPanel('intro', classname="full"), InlinePanel('form_fields', label="Form fields"), FieldPanel('thank_you_text', classname="full"), MultiFieldPanel([ FieldRowPanel([ FieldPanel('from_address', classname="col6"), FieldPanel('to_address', classname="col6"), ]), FieldPanel('subject') ], "Email") ] class TagPage(Page): def serve(self, request): # Filter by tag tag = request.GET.get('tag') data = {} if tag: data['tag'] = tag data['pages'] = GenericPage.objects.live().filter(tags__name=tag) else: data['tags'] = Tag.objects.all return render(request, self.template, data) moderate_model(GenericPage, publication_date_field='date')
title = models.CharField("Title", max_length=200) slug = models.SlugField("Slug", unique=True) content = models.TextField("Content") publication_date = models.DateTimeField("Publication date") enable_comments = models.BooleanField("Enable comments", default=True) # Optional reverse relation, allow ORM querying: comments_set = CommentsRelation() class Meta: verbose_name = "Article" verbose_name_plural = "Articles" def __str__(self): return self.title def get_absolute_url(self): return reverse("article-details", kwargs={"slug": self.slug}) # Optional, give direct access to moderation info via the model: comments = property(get_comments_for_model) comments_are_open = property(comments_are_open) comments_are_moderated = property(comments_are_moderated) # Give the generic app support for moderation by django-fluent-comments: moderate_model( Article, publication_date_field="publication_date", enable_comments_field="enable_comments", )