The models below show a simple ratio of GenericForeignKey. It has been tuned to allow Image to reuse 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
Currently, using ImageInline, a window with all the images in the system will appear inside another administrator of the model.
Is it possible for the built-in administrator to display the actual image model, showing only the images assigned to the edited model? Thus, the user can immediately see all the related information about the images attached to the added / edited model. In addition to the ability to add / remove related images.
Thank you in advance for your help.