You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ModifiedMedia model stores the modified metadata of a particular file. But currently, it's a semi-duplicate of Media including the fields. This is not ideal to maintain, specially if the fields change.
One alternative solution is Media to have a modified_media field pointing to a temporary Media instance. Whenever metadata is to be edited, the media is duplicated (new entry/id) and linked as modified_media. Once the changes have been accepted, the duplicated media instance can be deleted. In this way, modified_media will always have the same fields as Media (because it is a Media instance). Based on the documentation, the recommended way of doing this is using a self-referenced ForeignKey:
class Media(models.Model):
modified_media = models.ForeignKey('self', on_delete=models.CASCADE, verbose_name=_('mídia modificada'), help_text=_('Mídia temporária guardando os metadados modificados.'), related_name='modified_media'))
However, another solution is using Multi table inheritance. The advantage here is that the modified media will be on a separate table. They will not show up when we perform a regular query on Media (we don't want duplicated media showing up). This would look like this:
class Media(models.Model):
(...)
class ModifiedMedia(Media):
original_media = models.ForeignKey('Media', on_delete=models.SET_NULL, verbose_name=_('mídia original'), help_text=_('Mídia original com metadados antes das modificações.'), related_name='modified_media'))
The text was updated successfully, but these errors were encountered:
The
ModifiedMedia
model stores the modified metadata of a particular file. But currently, it's a semi-duplicate ofMedia
including the fields. This is not ideal to maintain, specially if the fields change.One alternative solution is
Media
to have amodified_media
field pointing to a temporaryMedia
instance. Whenever metadata is to be edited, the media is duplicated (new entry/id) and linked asmodified_media
. Once the changes have been accepted, the duplicated media instance can be deleted. In this way,modified_media
will always have the same fields asMedia
(because it is aMedia
instance). Based on the documentation, the recommended way of doing this is using a self-referenced ForeignKey:However, another solution is using Multi table inheritance. The advantage here is that the modified media will be on a separate table. They will not show up when we perform a regular query on Media (we don't want duplicated media showing up). This would look like this:
The text was updated successfully, but these errors were encountered: