Home > Net >  Will it be correct if property will change the data?
Will it be correct if property will change the data?

Time:07-11

    @property
    def check_too_much_sent_confirmation(self):
        if self._count_of_hashes_sent >= 3:
            if UTC.localize(datetime.now()) <= self.updated_at   timedelta(minutes=10):
                return True
            else:
                self.reset_count_of_hashes_sent()
        return False

    def reset_count_of_hashes_sent(self, commit=False):
        self._count_of_hashes_sent = 0
        self._save_if_commit(commit)

In the code above, check_too_much_sent_confirmation checks if the user can send the confirmation code again, he is given 3 attempts every 10 minutes.

self.reset_count_of_hashes_sent()

The line above resets the number of attempts.

Is it correct that a method is called from a property function that changes the data in the database? Or is it better to call this function separately?

CodePudding user response:

A property should just return data and do not change the state of a model/database.

Create a method which may check and increase at the same time.

Or change the property to just check and reuse the property in the new method to check & increase.

  • Related