How do i get a value points from one-to-one table that related to current user on a website. In short how to get current_user_points like a current_user_id in this code
views.py
current_user_points = userprofiles.points
current_user_id = request.user.id
models.py
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
points = models.IntegerField(default=100)
telegramID = models.CharField(max_length=9, blank=True)
CodePudding user response:
Just use reversed relation. Assuming that it has related UserProfile
:
user = User.objects.get(id=1)
user.userprofile.points