wlanslovenija / django-tastypie-mongoengine

MongoEngine support for django-tastypie.
Other
72 stars 59 forks source link

references to dynamic documents #63

Open eelkeh opened 10 years ago

eelkeh commented 10 years ago

Let's say I have an article document with a list of references to image documents (which are dynamic).

class Image(DynamicDocument):
   something = StringField(required=True)

class Article(Document):
    images = ListField(ReferenceField(Image))

class ArticleMongoResource(MongoEngineResource):
    images = fields.ReferencedListField(of='app.api.ImageResource',
                                    attribute='images', full=True, null=True)

class ImageResource(MongoEngineResource):
   ...   

Now when I POST and add a number of arbitrary fields to images they don't seem to picked up, it seems to behave like a regular document (not dynamic), i.e.:

{ "images": [{"something": "abc", "dynamic": "def" }]

Here the "dynamic" field isn't picked up and saved, it is stripped somewhere. Is there anything wrong with above code? What could be the case here?

eelkeh commented 10 years ago

Any idea what could cause this behaviour?

mitar commented 10 years ago

Sorry. No time to check this currently. Can you check if we have a test to handle dynamic documents and compare? Does it work if there is reference list field, but is dynamic document a subdocument? Can you make a pull request with a test?

eelkeh commented 10 years ago

Added a test for a dynamic document which fails.

mitar commented 10 years ago

OK, as I said, I don't have much time for this now. Sorry. Will try to get back, but don't expect it too fast. So the whole interface between Tastypie and Mongoengine is a bit hackish, so for special features like this we might add another hack.