diff --git a/django_code/apps/cloudmanager/admin.py b/django_code/apps/cloudmanager/admin.py index 90c5cde..188fe4b 100644 --- a/django_code/apps/cloudmanager/admin.py +++ b/django_code/apps/cloudmanager/admin.py @@ -38,6 +38,11 @@ def scale_down_deploy(modeladmin, request, queryset): messages.SUCCESS, ) +@admin.action(description="create_entry") +def create_entry(modeladmin, request, queryset): + print("simpsons_data_object.create(season=2, episode=3, url='google.com'', seen=True)") + #call function to trigger refresh of all deploy + class ActiveAtHourFilter(admin.SimpleListFilter): title = 'Active at hour' parameter_name = 'active_at_hour' diff --git a/django_code/apps/cloudmanager/models.py b/django_code/apps/cloudmanager/models.py index 1f9b526..69f1a3f 100644 --- a/django_code/apps/cloudmanager/models.py +++ b/django_code/apps/cloudmanager/models.py @@ -55,4 +55,4 @@ class Machine_Data(models.Model): replicas = models.IntegerField() class Meta: db_table = 'machine' - \ No newline at end of file + diff --git a/django_code/apps/random_simpsons/admin.py b/django_code/apps/random_simpsons/admin.py index d1fc630..40d0543 100644 --- a/django_code/apps/random_simpsons/admin.py +++ b/django_code/apps/random_simpsons/admin.py @@ -1,7 +1,6 @@ from django.contrib import admin,messages from django.utils.translation import ngettext -from .models import SimpsonsData - +from .models import SimpsonsData,simpsons_data_object # Register your models here. @@ -35,14 +34,16 @@ def make_unseen(modeladmin, request, queryset): messages.SUCCESS, ) - +@admin.action(description="create_entry") +def create_entry(modeladmin, request, queryset): + simpsons_data_object.create(season=2, episode=3, url="google.com", seen=True) @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] + actions = [make_seen,make_unseen,create_entry] def get_queryset(self, request): return super().get_queryset(request).using(DB) diff --git a/django_code/apps/random_simpsons/models.py b/django_code/apps/random_simpsons/models.py index 07f611f..659628d 100644 --- a/django_code/apps/random_simpsons/models.py +++ b/django_code/apps/random_simpsons/models.py @@ -8,3 +8,5 @@ class SimpsonsData(models.Model): class Meta: db_table = 'episodes' + +simpsons_data_object = SimpsonsData.objects.using('simpsons_db') \ No newline at end of file diff --git a/django_code/apps/random_simpsons/views.py b/django_code/apps/random_simpsons/views.py index cb8bda7..c0b32df 100644 --- a/django_code/apps/random_simpsons/views.py +++ b/django_code/apps/random_simpsons/views.py @@ -1,7 +1,7 @@ from django.http import HttpResponse from django.db.models import Count from django.shortcuts import redirect -from apps.random_simpsons.models import SimpsonsData +from apps.random_simpsons.models import SimpsonsData,simpsons_data_object import random @@ -9,7 +9,7 @@ def hello(request): return HttpResponse('

Hello Simpsons view!

') def episode_generator(request): - simpsons_data_object = SimpsonsData.objects.using('simpsons_db') + #simpsons_data_object = SimpsonsData.objects.using('simpsons_db') boolean_restart = True; while (boolean_restart):