closeio / flask-mongorest

Restful API framework wrapped around MongoEngine
Other
522 stars 87 forks source link

Exclude field #112

Closed Odselmaa closed 4 years ago

Odselmaa commented 7 years ago

How to exclude one or more fields? Because I have so many fields and need to exclude one field

bitrot-sh commented 6 years ago

While defining your Resource based class, include the fields that you want to return. Example:

class UserResource(Resource):
    document = User
    filters = {
        'email': [Exact, IExact, Contains, IContains],
        'username': [Exact, IExact, Contains, IContains],
    }
    fields = ['username']

The above example will only return the field username (excluding email).

sunitsingh1 commented 4 years ago

How to modified field value at the time of post request (i want to change the value of request data fields) in Resource() class

AlecRosenbaum commented 4 years ago

I think you should be able to do something like this:

class UserResource(Resource):
    document = User
    fields = ['username', 'upper_username']

    def upper_username(self, obj):
        return obj.username.upper()
sunitsingh1 commented 4 years ago

No this one return only not saving in db. I want to change the value of field and then store in db At a time of post request.

On Wed, Dec 4, 2019, 2:04 AM Alec Rosenbaum notifications@github.com wrote:

I think you should be able to do something like this:

class UserResource(Resource): document = User fields = ['username', 'upper_username']

def upper_username(self, obj): return obj.username.upper()

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/closeio/flask-mongorest/issues/112?email_source=notifications&email_token=AIOZY4KDOGWYH3G2DA42HM3QW27FFA5CNFSM4DLHLGT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF2XFYI#issuecomment-561345249, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIOZY4LB36BCEYPEFB36PNLQW27FFANCNFSM4DLHLGTQ .

AlecRosenbaum commented 4 years ago

try overriding:

    def create_object(self, **kwargs):
        # custom stuff
        custom_val = self.raw_data.pop('custom_val')

        super().create_object(**kwargs)
sunitsingh1 commented 4 years ago

Basically i get the base64 data from request and i want to convert it in jpg and store in local system and it's path store in db . If you have any sample of code for this situation using flask_mongorest. Plz share

On Wed, Dec 4, 2019, 2:19 AM SUNIT KUMAR Singh sunitkumarsingh1@gmail.com wrote:

No this one return only not saving in db. I want to change the value of field and then store in db At a time of post request.

On Wed, Dec 4, 2019, 2:04 AM Alec Rosenbaum notifications@github.com wrote:

I think you should be able to do something like this:

class UserResource(Resource): document = User fields = ['username', 'upper_username']

def upper_username(self, obj): return obj.username.upper()

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/closeio/flask-mongorest/issues/112?email_source=notifications&email_token=AIOZY4KDOGWYH3G2DA42HM3QW27FFA5CNFSM4DLHLGT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF2XFYI#issuecomment-561345249, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIOZY4LB36BCEYPEFB36PNLQW27FFANCNFSM4DLHLGTQ .

AlecRosenbaum commented 4 years ago

I do not have sample code for that scenario.

sunitsingh1 commented 4 years ago

Ok I will try. Thank you

On Wed, Dec 4, 2019, 2:30 AM Alec Rosenbaum notifications@github.com wrote:

I do not have sample code for that scenario.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/closeio/flask-mongorest/issues/112?email_source=notifications&email_token=AIOZY4OP7A76BMHCLLF6FBDQW3CGHA5CNFSM4DLHLGT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF2ZP3Y#issuecomment-561354735, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIOZY4JND23B6J5W6NOV6BTQW3CGHANCNFSM4DLHLGTQ .

sunitsingh1 commented 4 years ago

I tried it's work but it not returning anything . How to return like earlier Plz help if any idea

On Wed, Dec 4, 2019, 2:35 AM SUNIT KUMAR Singh sunitkumarsingh1@gmail.com wrote:

Ok I will try. Thank you

On Wed, Dec 4, 2019, 2:30 AM Alec Rosenbaum notifications@github.com wrote:

I do not have sample code for that scenario.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/closeio/flask-mongorest/issues/112?email_source=notifications&email_token=AIOZY4OP7A76BMHCLLF6FBDQW3CGHA5CNFSM4DLHLGT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF2ZP3Y#issuecomment-561354735, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIOZY4JND23B6J5W6NOV6BTQW3CGHANCNFSM4DLHLGTQ .