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

Attribute inspection #92

Open
RazerM opened this issue Sep 2, 2017 · 0 comments
Open

Attribute inspection #92

RazerM opened this issue Sep 2, 2017 · 0 comments

Comments

@RazerM
Copy link
Contributor

RazerM commented Sep 2, 2017

Would a PR be accepted that pulled out part of this code:

attributes = {
(self.fields[field].dump_to or field): field
for field in self.fields
}
for field_name, value in iteritems(item):
attribute = attributes[field_name]
if attribute == ID:
ret[ID] = value
elif isinstance(self.fields[attribute], Meta):
if 'meta' not in ret:
ret['meta'] = self.dict_class()
ret['meta'].update(value)
elif isinstance(self.fields[attribute], BaseRelationship):
if value:
if 'relationships' not in ret:
ret['relationships'] = self.dict_class()
ret['relationships'][self.inflect(field_name)] = value
else:
if 'attributes' not in ret:
ret['attributes'] = self.dict_class()
ret['attributes'][self.inflect(field_name)] = value

into a separate function? Specifically, the part that creates a map of JSONAPI attributes to Marshmallow fields?

The use case I have in mind is being able to tell which attributes I'll end up with before dumping. I would still need to apply inflect(attribute) and check field_obj.load_only, but at least I don't have to rely on internal API.

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

1 participant