[Answer]-How to access a field from an extended user in Django?

1👍

You can do this: Add a related_name attribute to the OneToOneField and then reverse access it using the . accessor.

class userProfile(models.Model):
    user = models.OneToOneField(User, related_name='profile')
    USER_RATING_CHOICES = (("1 star", "1 Star(s)"), ("2 star", "2 Star(s)"), ("3 star", "3 Star(s)"), ("4 star", "4 Star(s)"), ("5 star", "5 Star(s)"))        
    userRating = models.CharField("User rating", max_length=6, choices=USER_RATING_CHOICES, default="1 star")

and then,

{% for listing in partListingTitle %}
    {{listing.postedBy.profile.userRating}}
{% endfor %}

Leave a comment