Reputation: 397
I have a table in database:
models.py
class Board(models.Model):
...
Now from python shell (manage.py shell), I can do:
Board._meta._name_map
But I can't access it in my views.py:
a = Board._meta._name_map
Error:
'Options' object has no attribute '_name_map'
There might be some other attributes missing too, so why is it?? How can I access this _name_map information?
Upvotes: 1
Views: 782
Reputation: 37364
_name_map
is a cache, not something you can rely on.
I think you'll be better off with this:
for field in Board._meta.fields:
if isinstance(field, ForeignKey):
k = field.name
# then whatever
At least assuming you don't already know the name of the field you're looking for, since you say get_field_by_name
doesn't help.
Upvotes: 1