As far as I know, there is no method for Django models like hasattr (). But there is a way to check if the Django model has a specific field.
To test this, I would recommend that you refer to the Django shell (Python):
$> python manage.py shell
Now import the User model:
$> from django.contrib.auth.models import User
Get model meta-information:
$> opts = User._meta
To check the field, use the following command:
$> opts.get_field('username')
In the case of a user model, the following message will be printed:
<django.db.models.fields.CharField object at 0x1024750>
, , , FieldDoesNotExist. .
: b-list.org: