From 17a7e173fee9a474732d9da381248ae613289e76 Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Tue, 16 Jun 2026 10:26:17 +0100 Subject: [PATCH] work on django admin --- django_code/apps/random_simpsons/admin.py | 41 +++++++++++++++++++++-- django_code/django_code/urls.py | 2 +- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/django_code/apps/random_simpsons/admin.py b/django_code/apps/random_simpsons/admin.py index 8c38f3f..6f8e167 100644 --- a/django_code/apps/random_simpsons/admin.py +++ b/django_code/apps/random_simpsons/admin.py @@ -1,3 +1,40 @@ -from django.contrib import admin - +from django.contrib import admin,messages +from django.utils.translation import ngettext +from .models import SimpsonsData # Register your models here. + + +@admin.action(description="Mark episode as seen") +def make_seen(modeladmin, request, queryset): + updated = queryset.update(seen="True") + modeladmin.message_user( + request, + ngettext( + "%d episode was successfully marked as seen.", + "%d episodes were successfully marked as seen.", + updated, + ) + % updated, + messages.SUCCESS, + ) + +@admin.action(description="Mark episode as not seen") +def make_unseen(modeladmin, request, queryset): + updated = queryset.update(seen="False") + modeladmin.message_user( + request, + ngettext( + "%d episode was successfully marked as not seen.", + "%d episodes were successfully marked as not seen.", + updated, + ) + % updated, + messages.SUCCESS, + ) + +@admin.register(SimpsonsData) +class EpisodeAdmin(admin.ModelAdmin): + list_display = ('season', 'episode', 'url', 'seen') + list_filter = ['seen'] + fields = ['season', 'episode', 'url', 'seen'] + actions = [make_seen,make_unseen] \ No newline at end of file diff --git a/django_code/django_code/urls.py b/django_code/django_code/urls.py index bb4da51..46d1839 100644 --- a/django_code/django_code/urls.py +++ b/django_code/django_code/urls.py @@ -30,7 +30,7 @@ from apps.website_redirection import apps as website_redirectionapp urlpatterns = [ -# path('admin/', admin.site.urls), + path('admin/', admin.site.urls), ################### Simpsons ################### path('hello/', random_simpsons.hello),