-
-
Save W1773ND/ebb43b6e134da0ac58f24a07e2cdbe4e to your computer and use it in GitHub Desktop.
Revisions
-
Alican Toprak revised this gist
Sep 22, 2020 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ class DjangoModel(models.Model): @classmethod def from_db(cls, db, field_names, values): -
Alican Toprak revised this gist
Sep 22, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,12 +22,12 @@ def DjangoModel(models.Model): :return: """ if hasattr(self, '_old_values'): if not self.pk or not self._old_values: return True for field in fields: if getattr(self, field) != self._old_values[field]: return True return False return True -
Alican Toprak renamed this gist
Jan 30, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Alican Toprak revised this gist
Jan 30, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ def DjangoModel(models.Model): if self.data_changed(['street', 'street_no', 'zip_code', 'city', 'country']): print("one of the fields changed") returns true if the model saved the first time and _old_values doesnt exist :param fields: :return: -
Alican Toprak revised this gist
Jan 30, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,6 +15,8 @@ def DjangoModel(models.Model): example: if self.data_changed(['street', 'street_no', 'zip_code', 'city', 'country']): print("one of the fields changed") return true if the model saved the first time and _old_values doesnt exist :param fields: :return: -
Alican Toprak revised this gist
Jan 30, 2017 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,10 @@ def DjangoModel(models.Model): def data_changed(self, fields): """ example: if self.data_changed(['street', 'street_no', 'zip_code', 'city', 'country']): print("one of the fields changed") :param fields: :return: """ -
Alican Toprak revised this gist
Jan 30, 2017 . No changes.There are no files selected for viewing
-
Alican Toprak created this gist
Jan 30, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ def DjangoModel(models.Model): @classmethod def from_db(cls, db, field_names, values): instance = super().from_db(db, field_names, values) instance._state.adding = False instance._state.db = db instance._old_values = dict(zip(field_names, values)) return instance def data_changed(self, fields): """ :param fields: :return: """ if hasattr(self, '_old_values'): if not self.id or not self._old_values: return True for field in fields: if getattr(self, field) != self._old_values[field]: return True return False return True