Django

Code

Ticket #7984 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

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

Reported by: philwo Assigned to: brosner
Milestone: 1.0 Component: django.contrib.admin
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

admin-inlineviewonsite.diff (2.5 kB) - added by julianb on 07/27/08 15:56:15.

Change History

07/27/08 15:20:28 changed by julianb

  • needs_better_patch changed.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • milestone set to 1.0 beta.

I can confirm that. Looks like a bug.

07/27/08 15:56:15 changed by julianb

  • attachment admin-inlineviewonsite.diff added.

07/27/08 15:57:09 changed by julianb

  • has_patch set to 1.

07/28/08 23:28:50 changed by brosner

  • owner changed from nobody to brosner.
  • status changed from new to assigned.

08/01/08 15:49:00 changed by brosner

  • milestone changed from 1.0 beta to 1.0.

08/26/08 13:08:18 changed by brosner

  • status changed from assigned to closed.
  • resolution set to fixed.

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


Add/Change #7984 (Admin "View on site" builds wrong URL with inline models)




Change Properties
Action