-
Notifications
You must be signed in to change notification settings - Fork 301
Serializer resource_name
for nested objects is not used
#74
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
Comments
resource_name
for nested objects is not used
We just stumbled upon the It would be very beneficial to us, if we could configure how the Otherwise we're forced to use "single worded" models. |
This should be fixed by #76 when it is merged. |
#76 does centralize the formatting but still
The serializer |
Thanks for the comment on |
Sweet. Let me know if I can help! |
Since this issue is not fixed by 64f8a6b I'll reopen this as a reminder that the reported problem still exists. |
@mkohram could you please test code from branch feature/compound_documents to see if it fixes this issue? |
I'm afraid not. Looking through the code I believe
...
if isinstance(field, ListSerializer):
relation_data = list()
serializer_data = resource.get(field_name)
resource_instance_queryset = list(relation_instance_or_manager.all())
if isinstance(serializer_data, list):
for position in range(len(serializer_data)):
nested_resource_instance = resource_instance_queryset[position]
# something along the lines of
# nested_resource_instance_type = field.child.Meta.resource_name
nested_resource_instance_type = get_resource_type_from_instance(nested_resource_instance)
relation_data.append(OrderedDict([
('type', nested_resource_instance_type),
('id', encoding.force_text(nested_resource_instance.pk))
]))
data.update({field_name: {'data': relation_data}})
continue A check on Other Also my relationships don't make it into the |
actually looking closer, looks like the serializer = field.child
relation_type = get_resource_type_from_serializer(serializer) We just need that up in |
@mkohram I know, this is what I changed in the branch (if you check the diff of the latest commit) II had forgot the lines in |
@mkohram would you mind testing again please ? |
OK. One more ... If the field is defined as |
@mkohram Since get_resource_type_from_instance uses the model instance solely so I believe a similar I have gotten around this issue for the most part by performing some long overdue renames to models which was trivial with RenameModel from django. The last holdout use case is that my user model is called |
@scottfisk I haven't had the time to look too closely yet but I think |
@mkohram you are correct, if the serializer or view has an attribute |
@mkohram @scottfisk @leifurhauks - We still need help on this, PRs could be applied to pr #145 so we could all contribute. |
This should be fixed by the added feature in #145 - I'll close this now but feel free to reopen if the issue persists |
Nested serializers don't use
resource_name
for thetype
. In the example below thetype
for the child would show something likenestedmodels
.Looking at the code it looks like in
utils.py
the only function that performs the correct checks to get thetype
isget_resource_name()
. All the other functions simply do something likerelation_type = inflection.pluralize(relation_model.__name__).lower()
without checking for aresource_name
on the serializer as the docs suggest. I could submit a PR if it makes sense to put these checks in place everywhere. Ideally a function likeget_related_resource_type()
should act as a getter fortype
so that we don't see these inconsistencies.The text was updated successfully, but these errors were encountered: