diff options
Diffstat (limited to 'archaeological_finds/models_finds.py')
| -rw-r--r-- | archaeological_finds/models_finds.py | 24 | 
1 files changed, 14 insertions, 10 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 19464838b..1b492148a 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -847,16 +847,20 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):      def duplicate(self, user):          model = self.__class__ -        # base fields -        table_cols = [field.name for field in model._meta.fields -                      if field.name not in PRIVATE_FIELDS or -                      field.name == 'order'] -        dct = dict([(attr, getattr(self, attr)) for attr in -                    table_cols]) -        dct['order'] += 1 -        dct['history_modifier'] = user -        new = self.__class__(**dct) -        new.save() + +        new = model.objects.get(pk=self.pk) + +        for field in model._meta.fields: +            # pk is in PRIVATE_FIELDS so: new.pk = None and a new +            # item will be created on save +            if field.name in PRIVATE_FIELDS: +                setattr(new, field.name, None) +        new.order = self.order + 1 +        new.history_order = user +        new.image.name = self.image.name +        # force_copy is necessary to not regenerate a thumb and resize +        # again the image +        new.save(force_copy=True)          # m2m fields          m2m = [field.name for field in model._meta.many_to_many  | 
