I have two model like this with following fields:
Profile:
-user(OTO Relation to User)
-address(OTO to Address)
-bio
-gender
...
Address:
-postal_code
-phone_number
-zip_code
I Also I have this list of fields name:
my_list = ["bio","gender","address.postal_code","address.phone_number", "address.zip_code"]
And finally I want to I create this @property
:
@property
def is_complete_profile(self):
''' Checks if all the fields have been filled '''
if self.pk:
for field_name in my_list:
value = getattr(self,field_name)
if not value:
return False
return True
else:
return False
But for related objects
this isn't the correct way and I got this error:
'Profile' object has no attribute 'address.postal_code'
How Can I use this list for get value of field of Profile
objects and related object values?
Notice:
I could solve this problem by using
eval
function, but because of this and this post, I preferred to throw this solution away.