Foreign keys add magic members
Because when you add one field to a class, you clearly want to add two fields to a class, and there's no need to consider the field you never asked to add to be something other than a field.
This commit is contained in:
parent
0b93eb78f4
commit
0439440f40
|
@ -29,14 +29,16 @@ class Theme(models.Model):
|
|||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
from django.db.models.fields.related_descriptors import ForeignKeyDeferredAttribute
|
||||
def set_fields(klass):
|
||||
fields = {}
|
||||
fields = []
|
||||
for n in dir(klass):
|
||||
assert n != "_fields"
|
||||
v = getattr(klass, n)
|
||||
if isinstance(v, models.Field):
|
||||
fields.add(n)
|
||||
if not hasattr(v, 'field'): continue
|
||||
if not isinstance(v.field, models.Field): continue
|
||||
if isinstance(v, ForeignKeyDeferredAttribute): continue
|
||||
fields.append(n)
|
||||
setattr(klass, '_fields', fields)
|
||||
return klass
|
||||
|
||||
|
|
Loading…
Reference in New Issue