[Answer]-Check Dependency When Delete a object on Django

1👍

You can do that by accessing the reverse ForeignKey field from Role. Something like:

if role_instance.userprofile_set.all():
   print "Care, role is related to userprofile instances"
else:
   print "You are safe to go" 
👤argaen

0👍

I think you are expecting this

role = Role.objects.get(name_role="rolename")
role.user_profile_set.all() #check if any before delete

Try this also

role.userprofile_set.all()

Leave a comment