views:

230

answers:

2

I have simple models with generic relations from this example at the Django Project:

class Image(models.Model):
    image = models.ImageField(upload_to="images")

class ImageLink(models.Model):
    image = models.ForeignKey(Image)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey("content_type", "object_id")

class Product(models.Model):
    name = models.CharField(max_length=100)

It's very simple to show inline ImageLink objects on the admin form of Product. It is demonstrated in the Django docs.

Can anyone suggest how have related ImageLinks inline on the admin form of an Image model?

IMPORTANT UPDATE: Updated example of model, becourse with previous, as Daniel sayd, it's not need to show objects inline.

A: 

You don't have any related Products to show inline. Generic foreign keys, like normal ones, are one-to-many, with the 'one' side of the relation being the one containing the foreign key field. So in your case you still only have one Product for each Image, so there is no inline set to show.

Daniel Roseman
You are absolutelly right. I have mistake in my example. And I know how to solve my issue now.
ramusus
A: 

It's neccessary use generic.GenericTabularInline for showing ImageLink objects inline on the Product form, as demonstrated in the Django docs.

But if we need to show related ImageLink inline on the Image form, it can be done with simple child of admin.TabularInline class.

It's very simple solution. I think I'm stupid not to guess it right away.

ramusus