1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #36063 -- Made a FileField navigate to the object admin change page when in list_display_links.

This commit is contained in:
antoliny0919
2025-01-05 18:58:03 +09:00
committed by Sarah Boyce
parent 6a1a9c0ead
commit a9c79b4629
5 changed files with 30 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.core.paginator import Paginator
from .models import Band, Child, Event, GrandChild, Parent, ProxyUser, Swallow
from .models import Band, Child, Event, Genre, GrandChild, Parent, ProxyUser, Swallow
site = admin.AdminSite(name="admin")
@@ -157,6 +157,14 @@ class NoListDisplayLinksParentAdmin(admin.ModelAdmin):
site.register(Parent, NoListDisplayLinksParentAdmin)
class ListDisplayLinksGenreAdmin(admin.ModelAdmin):
list_display = ["name", "file"]
list_display_links = ["file"]
site.register(Genre, ListDisplayLinksGenreAdmin)
class SwallowAdmin(admin.ModelAdmin):
actions = None # prevent ['action_checkbox'] + list(list_display)
list_display = ("origin", "load", "speed", "swallowonetoone")

View File

@@ -32,6 +32,7 @@ class GrandChild(models.Model):
class Genre(models.Model):
name = models.CharField(max_length=20)
file = models.FileField(upload_to="documents/", blank=True, null=True)
class Band(models.Model):

View File

@@ -1057,6 +1057,16 @@ class ChangeListTests(TestCase):
link = reverse("admin:admin_changelist_parent_change", args=(p.pk,))
self.assertNotContains(response, '<a href="%s">' % link)
def test_link_field_display_links(self):
self.client.force_login(self.superuser)
g = Genre.objects.create(name="Blues", file="documents/blues_history.txt")
response = self.client.get(reverse("admin:admin_changelist_genre_changelist"))
self.assertContains(
response,
'<a href="/admin/admin_changelist/genre/%s/change/">'
"documents/blues_history.txt</a>" % g.pk,
)
def test_clear_all_filters_link(self):
self.client.force_login(self.superuser)
url = reverse("admin:auth_user_changelist")