This file contains 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 characters
def contribute_to_class(self, cls, name, private_only=False): | |
""" | |
Register the field with the model class it belongs to. | |
If private_only is True, create a separate instance of this field | |
for every subclass of cls, even if cls is not an abstract model. | |
""" | |
self.set_attributes_from_name(name) | |
self.model = cls | |
cls._meta.add_field(self, private=private_only) | |
if self.column: | |
# Don't override classmethods with the descriptor. This means that | |
# if you have a classmethod and a field with the same name, then | |
# such fields can't be deferred (we don't have a check for this). | |
print(f"getattr(cls={cls}, self={self}), column={self.column}") | |
#print(f"cls.__dict__={cls.__dict__}, {self.attname}") | |
if not getattr(cls, self.attname, None): # <-- __get__ called invoked when self.attname is used! | |
setattr(cls, self.attname, self.descriptor_class(self)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment