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"
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()
- [Answer]-Model formset refresh extra field disappears
- [Answer]-Validate nested form in Django
- [Answer]-Django – Global name 'PayLaneRestClient' is not defined
- [Answer]-How to show subclass model in Django-admin inline form?
Source:stackexchange.com