rfostii / wadofstuff

Automatically exported from code.google.com/p/wadofstuff
0 stars 0 forks source link

Serialize Class Inheritance #5

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Attached a svn diff that adds serialization to subclasses of non-abstract
models.

Original issue reported on code.google.com by Flashing...@gmail.com on 30 Apr 2009 at 5:48

Attachments:

GoogleCodeExporter commented 9 years ago
Please resubmit the patch so that it doesn't reformat/re-style other parts of 
the
code e.g.

-    def __init__(self, *args, **kwargs):
+    def __init__( self, *args, **kwargs ):

Original comment by mattimus...@gmail.com on 30 Apr 2009 at 9:19

GoogleCodeExporter commented 9 years ago
Oopsala, didn't realize that, sorry. Here you go.

Original comment by Flashing...@gmail.com on 1 May 2009 at 9:33

Attachments:

GoogleCodeExporter commented 9 years ago
This is another approach of the patch, with subclass support.

Subclass works by going through the tree until we reach the real node. It's not 
an
efficient method because you have to hit the database lots of times per object. 
I
prefer doing something like:

def getRemoteDeviceIterator():
    classes = [ RemoteBluetoothDeviceFoundRecord, 
                RemoteBluetoothDeviceSDP,         
                RemoteBluetoothDeviceNoSDP,       
                RemoteBluetoothDeviceSDPTimeout,  
                RemoteBluetoothDeviceFileTry,     
                RemoteBluetoothDeviceFilesRejected, 
                RemoteBluetoothDeviceFilesSuccess   
        ]                                           
    a=list()                                        
    for b in classes:                               
        a.append(b.objects.filter(agentdevicerecord__commited=False).all())
    for clas in a:                                                         
        for element in clas:                                               
            yield element

because the list(QuerySet..)+list(QuerySet...) hits the database when you do 
the call
and gets you a lot of stuff in memory.

This patch also adds all the fields that are serializable not just the 
local_fields,
fields includes the parent class fields so there's no need for doing the weird 
things
from the previous patch.

I've tested the patch on lab, and going to do deployment tomorrow. Wanted to 
let you
guys know of it just in case.

Keep the good work,
Manuel

ps: With this patch I'm able to send the subclass and get it deserialized with 
django
serializer on the other end. The only thing I need to make sure is that the
ForeignKeys or M2M are there before I call save

Original comment by naranjo....@gmail.com on 14 Oct 2009 at 1:18

Attachments: