(self, cls, name)
| 183 | return self.apps.app_configs.get(self.app_label) |
| 184 | |
| 185 | def contribute_to_class(self, cls, name): |
| 186 | from django.db import connection |
| 187 | from django.db.backends.utils import truncate_name |
| 188 | |
| 189 | cls._meta = self |
| 190 | self.model = cls |
| 191 | # First, construct the default values for these options. |
| 192 | self.object_name = cls.__name__ |
| 193 | self.model_name = self.object_name.lower() |
| 194 | self.verbose_name = camel_case_to_spaces(self.object_name) |
| 195 | |
| 196 | # Store the original user-defined values for each option, |
| 197 | # for use when serializing the model definition |
| 198 | self.original_attrs = {} |
| 199 | |
| 200 | # Next, apply any overridden values from 'class Meta'. |
| 201 | if self.meta: |
| 202 | meta_attrs = self.meta.__dict__.copy() |
| 203 | for name in self.meta.__dict__: |
| 204 | # Ignore any private attributes that Django doesn't care about. |
| 205 | # NOTE: We can't modify a dictionary's contents while looping |
| 206 | # over it, so we loop over the *original* dictionary instead. |
| 207 | if name.startswith("_"): |
| 208 | del meta_attrs[name] |
| 209 | for attr_name in DEFAULT_NAMES: |
| 210 | if attr_name in meta_attrs: |
| 211 | setattr(self, attr_name, meta_attrs.pop(attr_name)) |
| 212 | self.original_attrs[attr_name] = getattr(self, attr_name) |
| 213 | elif hasattr(self.meta, attr_name): |
| 214 | setattr(self, attr_name, getattr(self.meta, attr_name)) |
| 215 | self.original_attrs[attr_name] = getattr(self, attr_name) |
| 216 | |
| 217 | self.unique_together = normalize_together(self.unique_together) |
| 218 | # App label/class name interpolation for names of constraints and |
| 219 | # indexes. |
| 220 | if not self.abstract: |
| 221 | self.constraints = self._format_names(self.constraints) |
| 222 | self.indexes = self._format_names(self.indexes) |
| 223 | |
| 224 | # verbose_name_plural is a special case because it uses a 's' |
| 225 | # by default. |
| 226 | if self.verbose_name_plural is None: |
| 227 | self.verbose_name_plural = format_lazy("{}s", self.verbose_name) |
| 228 | |
| 229 | # order_with_respect_and ordering are mutually exclusive. |
| 230 | self._ordering_clash = bool(self.ordering and self.order_with_respect_to) |
| 231 | |
| 232 | # Any leftover attributes must be invalid. |
| 233 | if meta_attrs != {}: |
| 234 | raise TypeError( |
| 235 | "'class Meta' got invalid attribute(s): %s" % ",".join(meta_attrs) |
| 236 | ) |
| 237 | else: |
| 238 | self.verbose_name_plural = format_lazy("{}s", self.verbose_name) |
| 239 | del self.meta |
| 240 | |
| 241 | # If the db_table wasn't provided, use the app_label + model_name. |
| 242 | if not self.db_table: |
no test coverage detected