I get this error 'int' object has no attribute 'save'
when i try to asign a new integer value to a field in my model. I have tried chaging the int to str(250)
but i want it to be an integer and not a string
profile_id = request.session.get('ref_profile')
if profile_id is not None:
recommended_by_profile = Profile.objects.get(id=profile_id)
print(profile_id)
p1 = recommended_by_profile.indirect_ref_earning 250
p1.save()
CodePudding user response:
You should do (assuming that indirect_ref_earning
is an IntegerField on Profile model):
profile_id = request.session.get('ref_profile')
if profile_id is not None:
recommended_by_profile = Profile.objects.get(id=profile_id)
print(profile_id)
recommended_by_profile.indirect_ref_earning = 250
recommended_by_profile.save()
CodePudding user response:
You are accessing the save
method in an int object, not on the model object hence you are getting that error.
You should do something like this when updating a certain field in your model:
recommended_by_profile.indirect_ref_earning = 250
not
p1 = recommended_by_profile.indirect_ref_earning 250