python - losing subclass fields when serializing in django? -
i see baffling , seems flatout bad behavior in serializing django objects. example, have models:
class mytag(tagbase): user = models.foreignkey(user) class mymptttag(mpttmodel, mytag): parent = treeforeignkey('self', null=true, blank=true, related_name='children') class mpttmeta: parent_attr = 'parent' which means mymppttag has fields of name, slug, user, parent. when serializers.serialize('json', mymppttag.object.all()), get: [{"fields": {"lft": 1, "level": 0, "tree_id": 29, "parent": null, "rght": 2}, "model": "index.mymptttag", "pk": 45}...]
why lose name, slug, , user, , how them back? thank you
on model design, have 2 tables in database:
yourapp_mytaghave primary key column (normal auto-increment column), columns inheritedtagbase(as longtagbaseabstract) , column user - foreign key model useryourapp_mymptttagtht have primary key column foreign keymytagmodel , columns mptt. there won't columns inheritedmytag.
that means: there no columns inherited mytag in model mymptttag, there references actual columns in mytag.
in serialization there 2 type of objects: mymptttag , mytag.
Comments
Post a Comment