python - Mongoengine few problems with reference field -


i have few problems mongoengine data manipulation. here models:

class resource(mongo.document):     slug = mongo.stringfield(max_length=255, primary_key=true)     name = mongo.stringfield(max_length=150, required=true)      meta = {        'allow_inheritance': true,     }   class linkresource(resource):     link_url = mongo.stringfield()   class fileresource(resource):     file = mongo.filefield()   class plan(mongo.document):     slug = mongo.stringfield(max_length=255, primary_key=true)     name = mongo.stringfield(max_length=150, required=true)     subplans = mongo.listfield(mongo.embeddeddocumentfield('self')     resources = mongo.listfield(mongo.referencefield(resource)) 

i need add resource plan, need move resource subplan (field of plan) or other plan.

then i'm add link resource plan next code:

res = linkresource.objects().get(slug='mylinkres') p = plan.objects().get(slug='myplan') p.update(add_to_set__resources=[res]) 

but got error "typeerror: <linkresource: linkresource object> not json serializable". (i'm use django rest framework).

  1. how can add resources subplan directly?
  2. how can move resource subplan or other plan ?
  3. how can serialize linkresource object?


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -