Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7984 closed (fixed)

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

Reported by: philwo Owned by: brosner
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 julianb 6 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 6 years ago by julianb

  • milestone set to 1.0 beta
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I can confirm that. Looks like a bug.

Changed 6 years ago by julianb

comment:2 Changed 6 years ago by julianb

  • Has patch set

comment:3 Changed 6 years ago by brosner

  • Owner changed from nobody to brosner
  • Status changed from new to assigned

comment:4 Changed 6 years ago by brosner

  • milestone changed from 1.0 beta to 1.0

comment:5 Changed 6 years ago by brosner

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:6 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.