2👍
✅
I assume you mean what ModelForm this field belongs to…
From looking at django.forms.Field and the __dict__
on a CharField, it appears that the answer is “no”. You’ll have to pass the Form or Model class as necessary.
👤rz.
0👍
Assuming you actually do mean a Model
, then you can get access to the class (but not, apparently the instance).
# This is is a model instance method:
field = self._meta.get_field_by_name('status')[0]
print field.model
Note, this uses the _meta
on the model class, which is technically implementation detail. Unlikely to be going away any time soon, though.
- [Answered ]-Django query with random
- [Answered ]-Django – how to pass multiple values to a templatetag
- [Answered ]-Django Integrity Error Handling
Source:stackexchange.com