Skip to content

Commit

Permalink
Add degree_editor links to admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
AaDalal committed Feb 7, 2024
1 parent c8d6cb2 commit aba624e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions backend/degree/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.contrib import admin
from django.conf.urls import url
from django.urls import reverse
from django.template.response import TemplateResponse
from django.utils.html import format_html

from degree.models import Degree, DegreePlan, DoubleCountRestriction, Rule, SatisfactionStatus

Expand All @@ -21,20 +23,25 @@ class DoubleCountRestrictionAdmin(admin.ModelAdmin):
@admin.register(Degree)
class DegreeAdmin(admin.ModelAdmin):
autocomplete_fields = ["rules"]
list_display = ["program", "degree", "major", "concentration", "year", "view_degree_editor"]

def get_urls(self):
def view_degree_editor(self, obj):
return format_html(
'<a href="{url}?id={id}">View in Degree Editor</a>',
id=obj.id,
url=reverse('admin:degree-editor')
)

def get_urls(self):
# get the default urls
urls = super().get_urls()
custom_urls = [
url(r'^degree-editor/$', self.admin_site.admin_view(self.security_configuration))
url(r'^degree-editor/$', self.admin_site.admin_view(self.degree_editor), name='degree-editor')
]
# Make sure here you place your added urls first than the admin default urls
return custom_urls + urls

# Your view definition fn
def security_configuration(self, request):
def degree_editor(self, request):
context = dict(
self.admin_site.each_context(request), # Include common variables for rendering the admin template.
self.admin_site.each_context(request)
)
return TemplateResponse(request, "degree-editor.html", context)

0 comments on commit aba624e

Please sign in to comment.