mrevutskyi / flask-restless-ng

A Flask extension for creating simple ReSTful JSON APIs from SQLAlchemy models.
https://flask-restless-ng.readthedocs.io
Other
64 stars 11 forks source link

Question in custom serialize? #2

Closed pedia closed 4 years ago

pedia commented 4 years ago

First:

I noticed in views.py API.get call self.serialize when instid provided call to_dict without instid

How about calling self.serialize in these two routines?

Second: How about custom serialize in this way:

class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode)

    @staticmethod
    def to_dict(inst):
        return dict(id=inst.id, name=inst.name)

And:

Provided model must have an id attribute

This is too distressed. What's the benefit with id?

mrevutskyi commented 4 years ago

hi, could you please link the exact code you are describing? I can't find any usage of to_dict

pedia commented 4 years ago

My bad, this code was in tag 0.17.0

to_dict was in views.py _paginated

self.serialize was in get

I think these code is refactored much changed since 1.0.0, ignored my question.