Skip to content

Commit

Permalink
handle non trivial fields when reorganizing inodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Oct 1, 2024
1 parent 6749065 commit 4340b7b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions finder/management/commands/reorganize_finder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.core.management.base import BaseCommand
from django.db.models.expressions import Value
from django.db.models.fields import BooleanField
from django.db.models.fields.related import ForeignKey, ManyToManyField

from finder.models.file import FileModel
from finder.models.inode import InodeModel
Expand All @@ -23,6 +22,11 @@ def reorganize(self):
if not issubclass(file_model, file.__class__):
self.stdout.write(f"Reorganize file {file}")
if not file_model.objects.filter(id=file.id).exists():
kwargs = {attr.name: getattr(file, attr.name) for attr in file._meta.get_fields()}
kwargs = {}
for attr in file._meta.get_fields():
if isinstance(attr, ForeignKey):
kwargs[attr.name] = getattr(file, attr.name)
elif not isinstance(attr, ManyToManyField):
kwargs[attr.name] = attr.value_from_object(file)
file_model.objects.create(**kwargs)
file.delete()

0 comments on commit 4340b7b

Please sign in to comment.