Skip to content

Commit

Permalink
Add link to project on admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Powers committed Dec 20, 2024
1 parent 5373f71 commit 1d1b1a2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion projects/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from django.utils.html import format_html
from django.urls import reverse

from allocations.models import Allocation
from projects.models import (
Expand Down Expand Up @@ -218,7 +219,24 @@ class ProjectAdmin(admin.ModelAdmin):
list_display = ["charge_code", "pi", "nickname", "title"]
search_fields = ["charge_code", "pi__username", "pi__email", "nickname", "title"]
list_filter = ["tag"]
readonly_fields = ["charge_code", "automatically_tagged", "join_url"]
readonly_fields = [
"charge_code_link",
"automatically_tagged",
"join_url",
]
fields = [
"charge_code_link",
"title",
"nickname",
"description",
"pi",
"join_url",
]

def charge_code_link(self, obj):
return format_html(
f'<a href="{reverse("projects:view_project", args=[obj.id])}" target="_blank">{obj.charge_code}</a>'
)

def join_url(self, obj):
return format_html(
Expand Down

0 comments on commit 1d1b1a2

Please sign in to comment.