#18433: "View on site" does not work in InlineModelAdmin when using custom 
primary
key field
-------------------------------+----------------------------
     Reporter:  jurgeni        |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  contrib.admin  |    Version:  1.4
     Severity:  Normal         |   Keywords:  admin template
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+----------------------------
 This bug appears when using custom primary key fields with different name
 than id, foreign key (or many to many field) relation between models,
 get_absolute_url defined for models and using InlineModelAdmin in Admin
 interface. For example the following case suffers this:

 models.py
 {{{
 from django.db import models

 class Model1(models.Model):
     my_own_pk = models.CharField(max_length=100, primary_key=True)
     name = models.CharField(max_length=100)

 class Model2(models.Model):
     my_own_pk = models.CharField(max_length=100, primary_key=True)
     name = models.CharField(max_length=100)
     other_model = models.ForeignKey(Model1)

     def get_absolute_url(self):
         return '/model2/'
 }}}

 admin.py
 {{{
 from django.contrib import admin
 from demo.models import Model1, Model2

 class Model2Inline(admin.TabularInline):
     model = Model2
     extra = 1

 class Model1Admin(admin.ModelAdmin):
     inlines = (Model2Inline,)


 admin.site.register(Model1, Model1Admin)
 admin.site.register(Model2)
 }}}

 Now the "View on site" for InlineModel Model2 in Model1 in admin interface
 does not work because the template uses field '''id''' for creating link
 instead of '''pk'''. In my case the link uri is
 http://localhost:8000/admin/r/14// that redirects nowhere. If the template
 is changed to use '''pk''' instead of '''id''' the link uri is
 http://localhost:8000/admin/r/14/<the value of the pk here>/ and redirect
 works. The bug is in both TabularInline and StackedInline templates.

 django/contrib/admin/templates/admin/edit_inline/stacked.html line 9:
 {{{
 {% if inline_admin_form.show_url %}<a href="../../../r/{{
 inline_admin_form.original_content_type_id }}/{{
 inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif
 %}
 }}}

 Should be:
 {{{
 {% if inline_admin_form.show_url %}<a href="../../../r/{{
 inline_admin_form.original_content_type_id }}/{{
 inline_admin_form.original.pk }}/">{% trans "View on site" %}</a>{% endif
 %}
 }}}

 django/contrib/admin/templates/admin/edit_inline/tabular.html line 30:
 {{{
 {% if inline_admin_form.show_url %}<a href="../../../r/{{
 inline_admin_form.original_content_type_id }}/{{
 inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif
 %}
 }}}

 Should be:
 {{{
 {% if inline_admin_form.show_url %}<a href="../../../r/{{
 inline_admin_form.original_content_type_id }}/{{
 inline_admin_form.original.pk }}/">{% trans "View on site" %}</a>{% endif
 %}
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18433>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to