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).
- how can add
resources
subplan
directly? - how can move
resource
subplan
or otherplan
? - how can serialize linkresource object?
Comments
Post a Comment