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, cls, name, private_only=False)
| 982 | self.verbose_name = self.name.replace("_", " ") |
| 983 | |
| 984 | def contribute_to_class(self, cls, name, private_only=False): |
| 985 | """ |
| 986 | Register the field with the model class it belongs to. |
| 987 | |
| 988 | If private_only is True, create a separate instance of this field |
| 989 | for every subclass of cls, even if cls is not an abstract model. |
| 990 | """ |
| 991 | self.set_attributes_from_name(name) |
| 992 | self.model = cls |
| 993 | cls._meta.add_field(self, private=private_only) |
| 994 | if self.column: |
| 995 | setattr(cls, self.attname, self.descriptor_class(self)) |
| 996 | if self.choices is not None: |
| 997 | # Don't override a get_FOO_display() method defined explicitly on |
| 998 | # this class, but don't check methods derived from inheritance, to |
| 999 | # allow overriding inherited choices. For more complex inheritance |
| 1000 | # structures users should override contribute_to_class(). |
| 1001 | if "get_%s_display" % self.name not in cls.__dict__: |
| 1002 | setattr( |
| 1003 | cls, |
| 1004 | "get_%s_display" % self.name, |
| 1005 | partialmethod(cls._get_FIELD_display, field=self), |
| 1006 | ) |
| 1007 | |
| 1008 | def get_filter_kwargs_for_object(self, obj): |
| 1009 | """ |
no test coverage detected