I have an image model:
class Image(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
image = models.ImageField()
I also have a model which has fields
class MyModel(models.Model):
logo = models.ImageField()
icon = models.ImageField()
images = generic.GenericRelation(Image)
I want logo
and icon
to also use the generic relation Image
. How can I do this?
I use the generic model Image
in many models so it has to be a generic relation. I just want to use the same model for all images even though it's icons, profile pictures or whatever.
The best would be if Django had a field generic.GenericOneToOneRelation(Image)
or something :-)
The only solution I can think of is
class MyModel(models.Model):
logo = models.ForeignKey(Image)
icon = models.ForeignKey(Image)
images = generic.GenericRelation(Image)
and then selecting logo
and icon
after uploading images
and excluding logo
and icon
from images
when I'm printing the images
related to this model. Would this be a good solution?