1👍
✅
Use self._meta.fields
, class members are available on instances as well:
class HelperMixin(object):
@property
def get_fields(self):
return [(field.name, field.value_to_string(self)) for field in self._meta.fields]
The differense between class UserProfile(models.Model, HelperMixin)
and class UserProfile(HelperMixin, models.Model)
lies in the MRO (method resolution order). It would seem natural to have the mixin before the base class, but as long as the base and the mixin does not have members with the same name it makes no difference.
Source:stackexchange.com