help needed, Here is a model with having the User model as a foreign key
class UserMembership(models.Model):
user = models.OneToOneField(User, related_name='user_membership', on_delete=models.CASCADE)
membership = models.ForeignKey(Membership, related_name='user_membership', on_delete=models.SET_NULL, null=True)
reference_code = models.CharField(max_length=100, default='', blank=True)
on my views i am checking if the user exists in the above table
def verify(request):
user = request.user
check_membership_status = UserMembership.objects.filter(user = user).exists()
if check_membership_status == True:
# do something
pass
inside the do something condition i want to print out the record of the user from the “UserMembership” model and extract the the record id. how can i do that