The models below show a simple GenericForeignKey relationship. It has been set up in this way to allow an Image to be reused by any other model.
class Image(models.Model):
name = models.CharField(max_length=150)
desc = models.TextField(max_length=400)
resource = models.ImageField(upload_to='imgs/generic/%Y/%m/%d')
def __unicode__(self):
return self.name
class ImageItem(models.Model):
image = models.ForeignKey(Image, related_name='items', db_index=True)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField(db_index=True)
object = generic.GenericForeignKey('content_type','object_id')
class Meta:
unique_together = (('image', 'content_type', 'object_id'),)
def __unicode__(self):
return u'%s [%s]' % (self.object, self.image)
class ImageInline(generic.GenericTabularInline):
model = ImageItem
At present using ImageInline within another model's admin will show a list box with all the images within the system.
Is it possible to get the inline admin to show the actual Image model instead, showing only the images assigned to the model being edited? Thus allowing the user to see immediately all the related info on the images attached to the model being added/edited. As well as being able to add/remove related images.
Thanks in advance for your help on this one.