Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to have an attribute defined as a struct of some sort? #50

Open
joegaudet opened this issue Feb 28, 2020 · 1 comment
Open

Comments

@joegaudet
Copy link

joegaudet commented Feb 28, 2020

I have a JSONAPI endpoint that returns nested value objects, such as a contact. Wondering if there's a way to express that here, or if jsonapi-requests only supports primitives?

Example:

class LogisticsDelivery(jsonapi_requests.orm.ApiModel):
    class Meta:
        type = 'logistics-deliveries'
        api = api

    contact = jsonapi_requests.orm.AttributeField('contact')

deliveries = LogisticsDelivery.get_list()
for delivery in deliveries:
    pprint(delivery.contact)

Which outputs

{'email': '[email protected]',
 'extension': None,
 'first-name': 'Vancouver',
 'last-name': 'Client',
 'phone-number': '+12122708174',
 'phone-type': 'none',
 'sms-number': '4797755354'}

What I'd love is to be able to define a data class that could wrap this dictionary in a real object, that would allow for getting / setting.

@joegaudet joegaudet changed the title Is there a way to have an attribute defined as a struct of some sort. Is there a way to have an attribute defined as a struct of some sort? Feb 28, 2020
@pguz
Copy link

pguz commented Apr 27, 2020

Hi,

Yes there is such a possibility. You need to use jsonapi_requests.orm.RelationField('contact')
where contact is within Meta field:

class ConatactClass(jsonapi_requests.orm.ApiModel):
    class Meta:
        type = 'contact'
        api = api
  ...

Regards,
Paweł

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants