MeanPug / django-gsheets

Django app for keeping models and google sheets synced
https://www.meanpug.com/sync-data-to-and-from-google-sheets-with-django-gsheets/
MIT License
60 stars 25 forks source link

ValidationError on BooleanField #5

Closed sheiun closed 4 years ago

sheiun commented 4 years ago

When I pull TRUE or FALSE value from sheet it shows:

Exception has occurred: ValidationError
['“FALSE” value must be either True or False.']

But when I type True in sheet, it cast into all uppercase.

steinbachr commented 4 years ago

@sheiun one thing you should be able to do as a workaround is define a clean_FIELD_data method (where FIELD is the name of the field - from the sheet - that you need to convert). Inside that method, set the boolean value as appropriate

sheiun commented 4 years ago

@steinbachr it seems still not work after define clean_{FIELD}_data method in model.

I thought the problem is there isn't the clean_xxx_data method in self when execute upsert_model_data method.

p.s. I'd updated to 0.0.9.

steinbachr commented 4 years ago

one other thing to try @sheiun, can you try defining a clean_row_data staticmethod on the model subclassing the mixin? That method takes row_data (a dict of row data from the sheet prior to upsert) and returns a dict of the data which will be used for the upsert operation. Can you try doing the transform there?

sheiun commented 4 years ago

one other thing to try @sheiun, can you try defining a clean_row_data staticmethod on the model subclassing the mixin? That method takes row_data (a dict of row data from the sheet prior to upsert) and returns a dict of the data which will be used for the upsert operation. Can you try doing the transform there?

Doing sth like this?


class MyModel(SheetPullableMixin, models.Model):
    is_xxx = BooleanField()

    @staticmethod
    def clean_row_data(row_data):
        row_data['is_xxx'] = row_data['is_xxx'] == 'TRUE'
        return row_data
sheiun commented 4 years ago

@steinbachr Thanks it works. And if doing the change in my pull request that can also transform by using clean_{field}_data.