diff options
| author | Adam Johnson <me@adamj.eu> | 2024-03-08 11:50:11 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2024-03-09 16:14:18 +0100 |
| commit | faeb92ea13f0c1b2cc83f45b512f2c41cfb4f02d (patch) | |
| tree | b22317d92c4968949f29b5660fd73c96799e5d2c | |
| parent | 73df8b54a2fab53bec4c7573cda5ad8c869c2fd8 (diff) | |
Fixed #35270 -- Optimized model's Options._property_names.
co-authored-by: Nick Pope <nick@nickpope.me.uk>
| -rw-r--r-- | django/db/models/options.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py index 6f08feec25..f842faf0da 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -1,6 +1,5 @@ import bisect import copy -import inspect from collections import defaultdict from django.apps import apps @@ -969,11 +968,13 @@ class Options: @cached_property def _property_names(self): """Return a set of the names of the properties defined on the model.""" - names = [] - for name in dir(self.model): - attr = inspect.getattr_static(self.model, name) - if isinstance(attr, property): - names.append(name) + names = set() + for klass in self.model.__mro__: + names |= { + name + for name, value in klass.__dict__.items() + if isinstance(value, property) + } return frozenset(names) @cached_property |
