Add support for custom user models
This commit is contained in:
parent
3fad926559
commit
3a03cb71fe
5 changed files with 22 additions and 15 deletions
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from cms.models import PlaceholderField, CMSPlugin
|
||||
from cmsplugin_filer_image.models import ThumbnailOption
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings as dj_settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
@ -62,7 +62,8 @@ class Post(ModelMeta, TranslatableModel):
|
|||
"""
|
||||
Blog post
|
||||
"""
|
||||
author = models.ForeignKey(User, verbose_name=_('Author'), null=True, blank=True,
|
||||
author = models.ForeignKey(dj_settings.AUTH_USER_MODEL,
|
||||
verbose_name=_('Author'), null=True, blank=True,
|
||||
related_name='djangocms_blog_post_author')
|
||||
|
||||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
|
@ -217,11 +218,14 @@ class LatestPostsPlugin(CMSPlugin):
|
|||
|
||||
|
||||
class AuthorEntriesPlugin(CMSPlugin):
|
||||
authors = models.ManyToManyField(User, verbose_name=_('Authors'),
|
||||
limit_choices_to={'djangocms_blog_post_author__publish': True}
|
||||
)
|
||||
latest_posts = models.IntegerField(_(u'Articles'), default=settings.BLOG_LATEST_POSTS,
|
||||
help_text=_('The number of author articles to be displayed.'))
|
||||
authors = models.ManyToManyField(
|
||||
dj_settings.AUTH_USER_MODEL, verbose_name=_('Authors'),
|
||||
limit_choices_to={'djangocms_blog_post_author__publish': True}
|
||||
)
|
||||
latest_posts = models.IntegerField(
|
||||
_(u'Articles'), default=settings.BLOG_LATEST_POSTS,
|
||||
help_text=_('The number of author articles to be displayed.')
|
||||
)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s latest articles by author" % self.latest_posts
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
{% block blog_meta %}
|
||||
<ul class="post-detail">
|
||||
<li>
|
||||
{% trans "by" %} <a href="{% url 'djangocms_blog:posts-author' post.author.username %}">{{ post.author.get_full_name }}</a>
|
||||
{% trans "by" %} <a href="{% url 'djangocms_blog:posts-author' post.author.get_username %}">{{ post.author.get_full_name }}</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ post.date_published|date:"M d, Y" }}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<h3>{% trans "Authors" %}</h3>
|
||||
<ul class="blog-authors">
|
||||
{% for author in instance.get_authors %}
|
||||
<li><a href="{% url 'djangocms_blog:posts-author' author.username %}">
|
||||
<li><a href="{% url 'djangocms_blog:posts-author' author.get_username %}">
|
||||
{{ author.get_full_name }}
|
||||
<span>(
|
||||
{% if author.count > 0 %}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
{% block blog_meta %}
|
||||
<ul class="post-detail">
|
||||
<li>
|
||||
{% trans "by" %} <a href="{% url 'djangocms_blog:posts-author' post.author.username %}">{{ post.author.get_full_name }}</a>
|
||||
{% trans "by" %} <a href="{% url 'djangocms_blog:posts-author' post.author.get_username %}">{{ post.author.get_full_name }}</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ post.date_published|date:"M d, Y" }}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.utils.translation import get_language
|
||||
from django.utils.timezone import now
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.conf import settings as dj_settings
|
||||
from django.core.urlresolvers import resolve
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import get_language
|
||||
from django.views.generic import ListView, DetailView
|
||||
|
||||
from parler.views import ViewUrlMixin, TranslatableSlugMixin
|
||||
|
@ -11,6 +12,8 @@ from .models import Post, BlogCategory, BLOG_CURRENT_POST_IDENTIFIER
|
|||
from .settings import (BLOG_PAGINATION, BLOG_POSTS_LIST_TRUNCWORDS_COUNT,
|
||||
BLOG_USE_PLACEHOLDER)
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class BaseBlogView(ViewUrlMixin):
|
||||
|
||||
|
@ -107,11 +110,11 @@ class AuthorEntriesView(BaseBlogView, ListView):
|
|||
def get_queryset(self):
|
||||
qs = super(AuthorEntriesView, self).get_queryset()
|
||||
if 'username' in self.kwargs:
|
||||
qs = qs.filter(author__username=self.kwargs['username'])
|
||||
qs = qs.filter(**{'author__%s' % User.USERNAME_FIELD: self.kwargs['username']})
|
||||
return qs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs['author'] = User.objects.get(username=self.kwargs.get('username'))
|
||||
kwargs['author'] = User.objects.get(**{User.USERNAME_FIELD: self.kwargs.get('username')})
|
||||
return super(AuthorEntriesView, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue