Changes between Initial Version and Version 2 of Ticket #27757
- Timestamp:
- Jan 22, 2017, 4:44:31 AM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #27757
- Property Summary vIew_on_site is not working with inline models → view_on_site does not receive the get_absolute_url returning uri
-
Ticket #27757 – Description
initial v2 1 1 I am using Django-1.10 under Python-3.4.2. 2 2 3 Although ```view_on_site = True``` works great for the ```admin.ModelAdmin``` using the url provided by the ```get_absolute_url``` method of the model, inlines of the same model (```admin.StackedInline``` view) return a completely wrong url which points to the admin and contains a localized id (```/admin/<model>/r//1.234```). 3 {{{ 4 from django.db import models 4 5 5 Even if ```def view_on_site(self.obj)``` method is defined in the ```admin.StackedInline``` view, the result is ignored and the same localized url (```/admin/<model>/r//1.234```) is returned.6 6 7 class Product(models.Model): 8 name = models.CharField(verbose_name="Name", max_length=100, unique=True) 9 10 def get_absolute_url(self): 11 return "test-string/{0}".format(self.id) 12 13 14 class Flavor(models.Model): 15 product = models.ForeignKey(Product, verbose_name="Product") 16 name = models.CharField(verbose_name="Name", max_length=100) 17 18 19 def get_absolute_url(self): 20 return "test-string-2/{0}".format(self.id) 21 }}} 22 23 24 admin.py: 25 {{{ 26 from django.contrib import admin 27 from inline_online.models import Flavor, Product 28 29 30 class FlavorInline(admin.TabularInline): 31 model = Flavor 32 33 34 class ProductAdmin(admin.ModelAdmin): 35 list_display = ("id", "name") 36 inlines = [FlavorInline, ] 37 38 39 admin.site.register(Product, ProductAdmin) 40 41 42 class FlavorAdmin(admin.ModelAdmin): 43 view_on_site = True 44 45 46 admin.site.register(Flavor, FlavorAdmin) 47 }}} 48 49 The `view_on_site` link appears either in the main model admin view or in the inlines but the url is not the one returned from `get_absolute_url` method (example: `/admin/r/10/1`) 7 50 A very old ticket seem to reference the same issue: https://code.djangoproject.com/ticket/7984