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_mytag have primary key column (normal auto-increment column), columns inherited tagbase (as long tagbase abstract) , column user - foreign key model user
  • yourapp_mymptttag tht have primary key column foreign key mytag model , columns mptt. there won't columns inherited mytag.

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

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -