1
votes

Trying to build REST interface with tastypie and mongodb. I have schema

class ObjectsA(Document):
     attr1 = StringField(max_length=12, required=True)
class ObjectsB(Docuemnt):
     attr2 = ReferenceField(ObjectsA,
                        reverse_delete_rule=CASCADE, dbref=False)

After sending a GET request to ObjectsB i get json object with attr2 as "attr2": ObjectsA object"

How can I get attr1 in response from request to ObjectsB?

1

1 Answers

0
votes

I have found solutions. Maybe it's useful to someone. For me, it was not obvious. In the description for the resource class, you must describe all of the fields that have type ReferenceField for example:

from tastypie_mongoengine import fields

class CustomerResource(resources.MongoEngineResource):
    person = fields.ReferenceField(to=
        'test_project.test_app.api.resources.PersonResource',
         attribute='person', full=True)

    class Meta:
        queryset = documents.Customer.objects.all()
        allowed_methods = ('get', 'post', 'put', 'patch', 'delete')
        authorization = tastypie_authorization.Authorization()