# Conflicts: # apps/main/models.py # apps/news/admin.py # apps/news/models.py # apps/news/serializers.py # apps/news/views.py # project/settings/base.py # project/settings/production.py # requirements/base.txt
35 lines
849 B
Python
35 lines
849 B
Python
from django.contrib import admin
|
|
from django.conf import settings
|
|
|
|
from news import models
|
|
from .tasks import send_email_with_news
|
|
|
|
|
|
@admin.register(models.NewsType)
|
|
class NewsTypeAdmin(admin.ModelAdmin):
|
|
"""News type admin."""
|
|
list_display = ['id', 'name']
|
|
list_display_links = ['id', 'name']
|
|
|
|
|
|
def send_email_action(modeladmin, request, queryset):
|
|
news_ids = list(queryset.values_list("id", flat=True))
|
|
if settings.USE_CELERY:
|
|
send_email_with_news.delay(news_ids)
|
|
else:
|
|
send_email_with_news(news_ids)
|
|
|
|
|
|
send_email_action.short_description = "Send the selected news by email"
|
|
|
|
|
|
@admin.register(models.News)
|
|
class NewsAdmin(admin.ModelAdmin):
|
|
"""News admin."""
|
|
actions = [send_email_action]
|
|
|
|
|
|
@admin.register(models.NewsGallery)
|
|
class NewsGalleryAdmin(admin.ModelAdmin):
|
|
"""News gallery admin."""
|