Open bruvellu opened 12 months ago
Instead of manually passing all the fields to create a new ModifiedMedia
object, there are ways to create a copy of a model instance: https://docs.djangoproject.com/en/4.2/topics/db/queries/#copying-model-instances (still a bit involved).
See also:
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: