Opened 16 years ago

Closed 8 years ago

Last modified 8 years ago

#7984 closed Uncategorized (fixed)

Admin "View on site" builds wrong URL with inline models

Reported by: Philipp Wollermann Owned by: Brian Rosner
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've got a model "Product" and a model "Flavor": (stripped-down versions)

class Product(models.Model):
	name = models.CharField(verbose_name=_("Name"), max_length=100, unique=True)
	slug = models.SlugField(editable=False, blank=True)

	@permalink
	def get_absolute_url(self):
		return ("example.shop.views.view_product", (), {"slug": self.slug, "product": self.id})

	def save(self):
		self.slug = slugify(self.name)
		super(Product, self).save()

	def __unicode__(self):
		return u"%s" % (self.name,)

class Flavor(models.Model):
	product = models.ForeignKey(Product, verbose_name=_("Product"))
	name = models.CharField(verbose_name=_("Name"), max_length=100)
	slug = models.SlugField(editable=False, blank=True)

	@permalink
	def get_absolute_url(self):
		return ("example.shop.views.view_flavor", (), {"product_slug": self.product.slug, "flavor_slug": self.slug, "flavor": self.id, "product": self.product.id})

	def save(self):
		self.slug = slugify(self.name)
		super(Flavor, self).save()

	def __unicode__(self):
		return u"%s (%s)" % (self.product, self.name)

Now I look at them in admin and want to use the "View on site" button. Admin builds the following URLs:

Example product: http://example.com/admin/r/12/2/

Example flavor: http://example.com/admin/r/13/3/

Now I change my admin.py, so that Flavor is inline-edited in Product:

class FlavorInline(admin.TabularInline):
	model = Flavor

class ProductAdmin(admin.ModelAdmin):
	list_display = ("id", "name")
	inlines = [FlavorInline,]

Now admin builds the following URLs for "View on site":

Example product: http://example.com/admin/r/12/2/

Example inlined flavor: http://example.com/r//3/

Seems like the first parameter is not computed correctly on inlined-models!

Best regards,
Philipp

Attachments (1)

admin-inlineviewonsite.diff (2.5 KB ) - added by Julian Bez 16 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by Julian Bez, 16 years ago

milestone: 1.0 beta
Triage Stage: UnreviewedAccepted

I can confirm that. Looks like a bug.

by Julian Bez, 16 years ago

Attachment: admin-inlineviewonsite.diff added

comment:2 by Julian Bez, 16 years ago

Has patch: set

comment:3 by Brian Rosner, 16 years ago

Owner: changed from nobody to Brian Rosner
Status: newassigned

comment:4 by Brian Rosner, 16 years ago

milestone: 1.0 beta1.0

comment:5 by Brian Rosner, 16 years ago

Resolution: fixed
Status: assignedclosed

(In [8586]) Fixed #7984 -- 'View on site' links now work in inlines. Thanks philwo for the report and initial patch by julianb.

comment:6 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

comment:7 by George Tantiras, 8 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

Using Django-1.10 under Python-3.4.2, although view_on_site works great for the admin.ModelAdmin, inlines (admin.StackedInline) do not seem to use the model's get_absolute_url and return a completely wrong url which contains a localized id (/admin/<model>/r//1.234).

Last edited 8 years ago by George Tantiras (previous) (diff)

comment:8 by George Tantiras, 8 years ago

Resolution: fixed
Status: closednew

comment:9 by Claude Paroz, 8 years ago

Resolution: fixed
Status: newclosed

Please do not reopen such old bug reports, just create a new one and reference this issue in the description.

comment:10 by George Tantiras, 8 years ago

Thank you, I have createded a new issue.

https://code.djangoproject.com/ticket/27757

Note: See TracTickets for help on using tickets.
Back to Top