blender-studio/blog/admin.py
Anna Sirota f6ede7e3f7 Subscribers-only blog posts (#104416)
Adds `is_subscribers_only` column to Blog posts.

Posts with `is_subscribers_only == True` will

* not show up in the RSS feed;
* still show up at `/blog/` (`is_subscribers_only` is directly accessible in the templates);
* display a "Subscribe" banner in post's detail page instead of post's content;
   * comment section also won't be shown in this case.

Reviewed-on: #104416
Reviewed-by: Francesco Siddi <fsiddi@noreply.localhost>
2024-07-02 15:49:10 +02:00

64 lines
1.6 KiB
Python

from django.contrib import admin
from django.forms import Textarea
from blog.models import Post
from common.mixins import ViewOnSiteMixin
import search.signals
@admin.register(Post)
class PostAdmin(ViewOnSiteMixin, admin.ModelAdmin):
list_display = [
'__str__',
'film',
'author',
'is_subscribers_only',
'is_published',
'date_published',
'view_link',
]
list_filter = [
'is_subscribers_only',
'is_published',
'film',
]
def formfield_for_dbfield(self, db_field, **kwargs):
"""Override display of "excerpt" field.
Make it appear smaller than the content text area.
"""
if db_field.name == 'excerpt':
kwargs['widget'] = Textarea(attrs={'rows': 2, 'cols': 40})
return super().formfield_for_dbfield(db_field, **kwargs)
fieldsets = (
(
None,
{
'fields': [
'date_published',
'title',
'slug',
'category',
('author', 'contributors'),
'film',
'excerpt',
'content',
'attachments',
'header',
'thumbnail',
'is_subscribers_only',
'is_published',
],
},
),
)
autocomplete_fields = ['author', 'attachments', 'contributors', 'film']
search_fields = ['slug']
prepopulated_fields = {
'slug': ('title',),
}
actions = [search.signals.reindex]