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

added as_dict method for Pagination class #485

Closed
wants to merge 2 commits into from

Conversation

kalombos
Copy link
Contributor

flask_sqlalchemy/__init__.py Outdated Show resolved Hide resolved
flask_sqlalchemy/__init__.py Outdated Show resolved Hide resolved
test_sqlalchemy.py Outdated Show resolved Hide resolved
@davidism
Copy link
Member

I'm worried about returning items in the dict. Since the use of this method is for generating a JSON response, this implies that the items will be JSON serializable, a guarantee that we do not make.

@kalombos
Copy link
Contributor Author

kalombos commented Apr 4, 2017

I've fixed code style but i don't know what to do with items. Just remove it from dictionary?

@italomaia
Copy link

@kalombos if items always have to be properly parsed (meaning set again in the dictionary), then it probably makes sense to not have it in the output of to_dict. Example:

page = query.paginate()
result = page.to_dict()
result['items'] = schema.dump(page)

This syntax would also be quite nice:

page = query.paginate()
result = page.to_dict(schema.dump)

@@ -403,6 +403,17 @@ def iter_pages(self, left_edge=2, left_current=2,
yield num
last = num

def as_dict(self):
"""Create a dict with the pagination fields for use as a JSON response."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to mention that the result of this will probably not be directly JSON serializable. To serialize query results and models, the dev will need to implement a custom Flask.json_encoder class.

@davidism
Copy link
Member

davidism commented Jun 3, 2019

Hi, thanks for working on this! Based on further discussion in #482, I no longer think this is a feature we want to support right now, so I'm going to close it.

@davidism davidism closed this Jun 3, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2020
@davidism davidism removed this from the 3.x milestone Sep 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

None yet

4 participants