views:

160

answers:

2

Hello All,

I am new to programming and I just jumped in to Django and I need a bit of help. I downloaded the generic reviews model off of Google code and I have no clue how to implement it. Can anyone pass along some guidance on how to make this work with a 5 star ratings system? I would appreciate it. Thanks.

A: 

Depends on what you are using it for. From what I can see, it's designed for a blog of some description (see the reference to posts in the urls.py)

Apart from that, it looks pretty straight forward. Just install into your projects add to your model:

class MyModel(models.Model):
  ....
  review = models.ForeignKey(reviews.Reviews)

I guess. I'm not too hot either, but I'd imagine it's something like that.

datakid
That would create a relationship from MyModel to a single Review - probably not what OP is looking for
Chris Lawlor
A: 

From looking at the code:

You're mainly going to be using template tags. The reviews app uses generic relations - it stores the contenttype of your model along with its primary key, so you don't need to add any fields to your model.

To get a Review form for an instance of MyModel mymodel, use:

{% render_review_form for mymodel %}

There are similar tags for retrieving the total number of reviews:

{% get_review_count for mymodel as review_count %}

and the average rating:

{% get_review_avg_ratings for mymodel as rating %}

There are other variants of these tags to use if you don't have a reference to the desired model instance in your template. Check out the reviews/templatetags/reviews_tags.py file, it has some comments with example usage.

To retrieve the actual reviews, use the ORM:

reviews = Review.objects.filter(content_object=mymodel)

You can read more about using generic relations in the Django ORM in the Django Contenttypes documentation

Chris Lawlor
Thanks for your help guys. I have to look over this documentation and figure out how to work these template tags correctly.
firststepofthejourney