Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8595853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:32:18+00:00 2026-06-12T00:32:18+00:00

I would like to create a model method that will take the user (which

  • 0

I would like to create a model method that will take the “user” (which is a CharField) for
a given review and then return the “quote” associated with that user that is defined as part
of UserProfile. I am trying to create both the method as well as the template. The things I’ve tried so far haven’t seemed to work.

I know the best way to do this is probably make the “user” field within
Reviewbackup a ForeignKey to user, but I’d like to know how to be able to do it with a
method so I can learn.

models.py

class Reviewbackup(models.Model):
    review = models.CharField('Review', max_length = 2000)
    user = models.CharField('Username', max_length =  200)
    rating = models.IntegerField(max_length=2, choices=RATING_OPTIONS)
    product = models.ForeignKey(Productbackup)
    def __unicode__(self):
        return self.review

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    quote = models.CharField('About', max_length =  200, null=True, blank=True)
    website = models.URLField('Personal website/blog', null=True, blank=True)
    facebook = models.URLField('Facebook profile page', max_length = 200, null=True, blank=True)
    twitter = models.URLField('Twitter profile page', max_length = 200, null=True, blank=True)
    youtube = models.URLField('YouTube channel page', max_length = 200, null=True, blank=True)

views.py

def view_reviews(request, product_name):
    product = get_object_or_404(Productbackup, url_friendly=product_name)
    product_id = product.id
    #get reviews for the this product
    reviews = Reviewbackup.objects.filter(product_id=product_id).order_by("-created_on")
    return render_to_response('reserve/templates/view_reviews.html', {'reviews':reviews},
        context_instance=RequestContext(request))

template

{% for review in reviews %} 
{{review.user}}
<br>{{review.user.userprofile.quote}}
{% endfor %}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:32:20+00:00Added an answer on June 12, 2026 at 12:32 am

    If condition of the problem says “not to use a ForeignKey for user, but use CharField for username” you may add the method to your Reviewbackup model like:

    def get_user_quote(self):
        return UserProfile.objects.get(user__username=self.user).quote
    

    and use it in the template:

    {{ review.get_user_quote }}
    

    But you really should replace your user field to ForeignKey

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create an observer which will observe only one custom method.
I would like to create model binding functionality so a user can enter ','
I would like to create a Group model in Google App Engine and then
In my model I would like to create a scope that takes advantage of
i would like create a array of structure which have a dynamic array :
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create a class that runs something (a runnable) at regular
I'm using Rails 3 to create a project that will need a model called
I would like to know how can I create a form that submits to
My model has a method that will update several attributes in a model from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.