I'm working on a project that needs a ratings system where they can rate the quality of the houses. They'd be doing it from the admin panel, so it's not something that a visitor would rate.
For example, for each listing, they can rate it from 1-5 stars: Location: Room: Dining options: Community: Overall:
In my models.py file, I have this setup:
Class Listing (models.Model):
...
RATING_CHOICES = (
(1, 1),
(2, 2),
(3, 3),
(4, 4),
(5, 5),
)
location_rating = models.DecimalField(choices = RATING_CHOICES, max_digits=3, decimal_places=2)
room_rating = models.DecimalField(choices = RATING_CHOICES, max_digits=3, decimal_places=2)
dining_options_rating = models.DecimalField(choices = RATING_CHOICES, max_digits=3, decimal_places=2)
community_rating = models.DecimalField(choices = RATING_CHOICES, max_digits=3, decimal_places=2)
recreation_rooms_rating = models.DecimalField(choices = RATING_CHOICES, max_digits=3, decimal_places=2)
def __unicode__(self):
return self.name
def get_avg_rating(self):
avg_rating = (self.location_rating + self.room_rating + self.recreation_rooms_rating + self.dining_options_rating + self.community_rating) / 5
return avg_rating
I'd plan to display the ratings with a little CSS. Just putting room_rating or avg_rating in a template tag doesn't work, so I'm assuming I'd have to add some lines of code to views.py. I've checked the Django docs, but I'm still not sure how to go about this.
This seems like something that should be easy to do, but I'm not really sure where to start.