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 ImageLink
s inline on the admin form of an Image model?
IMPORTANT UPDATE: Updated example of model, because with previous, as Daniel said, we don't need to show objects inline.
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.