I'm trying to make the following fit in the Django ORM. Having a Publish
model which manages the publication of different kind of types of content (other models). This so I can easily do Publish.objects.all()
and order them by date. I made a generic model as the following:
class Publish(models.Model):
""" Intermediary model for displaying and managing different types of content """
status = models.IntegerField(_('status'), choices=STATUS_CHOICES, default=1)
publish = models.DateTimeField(_('publish'), default=datetime.datetime.now)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
The problem is that I want to attach this to different models. This has to be a OneToMany
relationship. Because an article can only have one publication date. A generic relation is, as far as I know, a ManyToMany
relationship.
I have tried restricting the max_num
and extra
in GenericTabularInline
in admin.py, but this isn't a great working solution. Does anyone know how to attach the Publish model to several different models, making it a required, one-to-many relationship? Many being the Publish model, one being for ex. an Article.