Re: Finding average
Please have a look at the aggregation docs and see if you can figure it out: https://docs.djangoproject.com/en/stable/topics/db/aggregation/ On Friday, October 2, 2015 at 2:46:39 AM UTC-4, Bhanu Kathuria wrote: > > I have attached my model files and template files. Please tell how can i > find avg of rating for a particular college. In current format it is > displaying rating of all colleges correctly. > Along with this I also want to add avg ratings for college. > I have used foriegn key in this. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/61afabd5-b57b-4d9d-9fbd-aa6b2d7f95a3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Finding average
I have attached my model files and template files. Please tell how can i find avg of rating for a particular college. In current format it is displaying rating of all colleges correctly. Along with this I also want to add avg ratings for college. I have used foriegn key in this. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5f44b185-b1f1-4e94-8382-f9f81f62de02%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. import datetime from django.db import models from django.utils import timezone # Create your models here. class College(models.Model): college_text=models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.college_text class Rating(models.Model): college=models.ForeignKey(College) rating=models.BigIntegerField() views=models.CharField(max_length=200) def __unicode__(self): return self.views {{college.college_text}} {% for rating in college.rating_set.all %} {{rating.rating}} {% endfor %} {% if latest_college_list %} {% for college in latest_college_list %} {{ college.college_text }} {% endfor %} {% else %} No polls are available. {% endif %}