Skip to content

Added support for adding meta objects from serializers #170

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

Merged
merged 5 commits into from
Dec 17, 2015

Conversation

jerel
Copy link
Member

@jerel jerel commented Dec 11, 2015

Solves #154.

By declaring a meta_fields property on the serializer's Meta class meta data can be added to the:

  • meta key of each item in a list serializer (a blog entry)
  • meta key of a single data object (a blog)

By declaring a get_root_meta function on a serializer data can be added to the:

  • top level meta object
{
  "data": [
    {
      "type": "entry",
      "id": "1",
      "attributes": {
        "title": "Test",
      },
      // set by EntrySerializer `meta_fields`
      "meta": {
        "bodyFormat": "text"
      }
    }
  ],
  // set by the `get_root_meta` function on EntrySerializer
  "meta": {
    "bar": "Baz"
  },
}

@jsenecal
Copy link
Member

Nice work here @jerel :)

@jerel jerel changed the title [WIP] Added support for meta objects in serializers and list serializers Added support for adding meta objects from serializers Dec 14, 2015
@jerel
Copy link
Member Author

jerel commented Dec 14, 2015

This is ready for review and feedback or merge

jsenecal added a commit that referenced this pull request Dec 17, 2015
Added support for adding meta objects from serializers
@jsenecal jsenecal merged commit 79b7c79 into develop Dec 17, 2015
@jsenecal jsenecal deleted the feature/meta branch December 17, 2015 18:22
@Elawphant
Copy link

Elawphant commented Dec 6, 2022

It seems, this does not work as expected.
I have extended rest_framework_json_api.serializers.ModelSerializer, added rest_framework_json_api.serializers.SerializerMethodField and get_my_field method to the serializer, and added my_field to Meta's meta_fields. However, instead of meta, my_field has appeared inside data.
get_root_meta on the serializer does nothing, either.

@auvipy
Copy link
Contributor

auvipy commented Dec 7, 2022

I think you should open a PR with a failing test

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

Successfully merging this pull request may close these issues.

4 participants