Answer the question
In order to leave comments, you need to log in
How to call a newly added field in a class in Django?
models.py
role_type = models.CharField(max_length=40, verbose_name="User Role")
group = models.ForeignKey(Group, on_delete=models.PROTECT, default=1, verbose_name='Group')
views.py
user = User .objects.get(username='my_user')
profile = Profile.objects.get(user=user)
user_role_group = profile.role.group
Throws
Traceback error (most recent call last):
File "", line 1, in
AttributeError: 'Role' object has no attribute 'group'
The group field was added later.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question