Changes between Initial Version and Version 1 of Ticket #28369, comment 3
- Timestamp:
- Jul 6, 2017, 4:40:50 PM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #28369, comment 3
initial v1 1 1 Well in some ways I think the patch creates some consistency given that there is already a hook for the "view on site" url in the admin. Grepping around, there could be some savings of lines get_*_url in the tests where basically the same hooks already exists. 2 2 3 Example: http://dpaste.com/1JFCGQG 3 Example: 4 5 {{{ #!python 6 # /parents/1/child_changelist 7 8 class ParentAdminSite(admin.Site): 9 def get_urls(self): 10 return super(ParentAdminSite, self).get_urls() + [ 11 url(r'^(?P<parent_id>%s)/children/', include(ChildObjectAdmin(imodels.ChildObject, self).urls))) 12 ] 13 14 15 class ChildObjectAdmin(admin.ModelAdmin): 16 def changelist_view(self, request, parent_id=None): 17 if parent_id: 18 self.parent_id = parent_id 19 self.parent = get_object_or_404(models.Parent, parent_id=parent_id) 20 return super(ChildObjectAdmin, self).changelist_view(request) 21 22 def get_queryset(self, request): 23 return super(ChildObjectAdmin, self).get_queryset(request).filter(parent=self.parent) 24 }}} 4 25 5 26 The current implementation presumes that a modeladmin is registered under a namespace with no other args or kwargs, but that may not be the case if someone has included additional url args in get_urls(). Almost everything about the admin works fine out of the box in this situation aside from the somewhat superficial problem of where the user is redirect post-save because, the urls that are being reversed deep in response_change (and subsequently response_post_save_change) are hard-coded.