Projet

Général

Profil

« Précédent | Suivant » 

Révision 6ec2e241

Ajouté par Benjamin Dauvergne il y a environ 10 ans

djommon/serializers/json: fix missing import and not handled case of new models

Voir les différences:

entrouvert/djommon/serializers/json.py
1 1
import json
2
import sys
2 3

  
3 4
from django.utils import six
4 5
from django.core.serializers.json import Serializer as JSONSerializer
......
26 27
        for obj in objects:
27 28
            Model = _get_model(obj['model'])
28 29
            if isinstance(obj['pk'], (tuple, list)):
29
                o = Model.objects.get_by_natural_key(*obj['pk'])
30
                obj['pk'] = o.pk
30
                try:
31
                    o = Model.objects.get_by_natural_key(*obj['pk'])
32
                except Model.DoesNotExist:
33
                    obj['pk'] = None
34
                else:
35
                    obj['pk'] = o.pk
31 36
        for obj in PythonDeserializer(objects, **options):
32 37
            yield obj
33 38
    except GeneratorExit:
......
35 40
    except Exception as e:
36 41
        # Map to deserializer error
37 42
        six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
43

  
44

  

Formats disponibles : Unified diff