Nested serialization of changes

68 views
Skip to first unread message

petros.m...@gmail.com

unread,
Apr 27, 2015, 2:32:38 PM4/27/15
to django-r...@googlegroups.com
Hello,

I am using the "follow" parameter to create revisions for models with related models. This creates serialized objects for all related objects and all the created serialized objects belong to the same revision. However, in the serialization of each object, its related objects are represented with just their ids. They are not expanded with their data. So, is there any way to have a serialization format for nesting all changes in a single representation?

For example if I have these models:

class ModelA(models.Model):
    field1
= ...
    field2
= ...
    related_field
= models.ForeignKey('ModelB')

class ModelB(models.Model):
    field1
= ...
    field2
= ...

I would like to have a representation for the serialized object of an instance of ModelA like this:

{pk: value, field1: value, field2: value, related_field: { pk: value, field1: value, field2: value } }

With that kind of nested serialization format I believe it would be easier to meet my ultimate goal, which is: To describe in a human-friendly way how instances of ModelA change from revision to revision, including changes in their related objects, changes in the related objects of their related objects, etc. The recursion would go as far as possible, but stop if an object has already been represented in a upper layer in the nested structure.

Dave Hall

unread,
Apr 28, 2015, 4:26:24 AM4/28/15
to django-r...@googlegroups.com
The django serialisation framework, which powered reversion, doesn’t support this, so I’m afraid not.

TBH, in a non-trivial set of models, featuring recursive relationships, the value of this feature is substantially reduced, since not everything can be represented using simple nesting. The current approaches tricky to get started with, but scales to any arbitrary set of models.
> --
> You received this message because you are subscribed to the Google Groups "django-reversion discussion group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-reversi...@googlegroups.com.
> To post to this group, send email to django-r...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-reversion.
> For more options, visit https://groups.google.com/d/optout.

signature.asc

petros.m...@gmail.com

unread,
Apr 28, 2015, 3:09:29 PM4/28/15
to django-r...@googlegroups.com
So, I guess that tracking what changed between revisions of objects along with their nested relationships is something that is not that easy to do with django-reversion. I wonder if there are any alternative frameworks for this kind of task...

petros.m...@gmail.com

unread,
Apr 29, 2015, 9:59:50 AM4/29/15
to django-r...@googlegroups.com, petros.m...@gmail.com
I am thinking of writing my own VersionAdapter subclass that overrides get_serialized_data() to provide nested serialization of related objects. What confuses me though is that VersionAdapter has no logic for deserializing. Where does deserialization of objects take place? Shouldn't it be part of the VersionAdapter?

Dave Hall

unread,
Apr 30, 2015, 12:30:51 PM4/30/15
to django-r...@googlegroups.com, petros.m...@gmail.com
Potentially, although it just uses the django serialisation framework behind the scenes. So far, the django serialization framework has been suitable for everyone’s needs.
signature.asc

keithca...@gmail.com

unread,
Feb 25, 2016, 9:59:15 AM2/25/16
to django-reversion discussion group
I'm sorry to dig up an old thread, but Dave, could you please clarify what you meant by the "current approach" here? 

Do you just mean that if we want ModelB's fields, we need to get a version of ModelB? 

If so, is there any official/automated way to get the version of B that was current as of a given ModelA version? Or do we need to use get_for_date(timestamp) for both A and B?

Thank you,
Keith

Dave Hall

unread,
Feb 26, 2016, 2:10:33 PM2/26/16
to django-reversion discussion group
If you have a Version instance, you can iterator over version.revision.version_set.all(). That includes all the related Version models.

Reply all
Reply to author
Forward
0 new messages