当前位置: 动力学知识库 > 问答 > 编程问答 >

django - Deserializing models and related models

问题描述:

I'm using django-reversion to store history of certain models. Some of these versioned models have "one to many" or "many to many" relations between them. django-reversion is properly configured to "follow" relations, so that all models are stored in the same revision.

I don't need to saved restore versions, I just need to be able to deserialize the models stored in a given revision and call a method on one of the deserialized models (for instance deserialized_model.object.get_summary()). Problem is that the method accesses related objects, and the related objects being used are the objects currently in database, and not the deserialized objects. I am deserializing all models I need at the same time.

Is there any way to make deserialized model instances use deserialized related model instances instead of actual instances? Note that this is not a django-reversion issue, it's more on the Django side.

EDIT:

I tried deceiving Django with prefetch_related. The idea was to store the deserialized objects as prefetched results, so that the related managers would retrieve objects from there and not from the database. Still no luck.

网友答案:

There is an issue tracker for django-reversion: https://github.com/etianen/django-reversion/issues

I would start there as the project owner may not be monitoring SO. You may also get answers from the ~90 contributors or ~60 watchers there.

网友答案:

As of now, the most complete answer to the question is: It is not possible to make deserialized model instances use other deserialized model instances as related objects.

分享给朋友:
您可能感兴趣的文章:
随机阅读: