Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModifiedMedia is a duplicated model #236

Open
bruvellu opened this issue Oct 31, 2023 · 1 comment
Open

ModifiedMedia is a duplicated model #236

bruvellu opened this issue Oct 31, 2023 · 1 comment
Labels
improvement Issues with improvements for existing features

Comments

@bruvellu
Copy link
Owner

bruvellu commented Oct 31, 2023

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'))
@bruvellu bruvellu added the improvement Issues with improvements for existing features label Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Issues with improvements for existing features
Projects
None yet
Development

No branches or pull requests

1 participant