Hi,
A complete and utter newbie seeks help.
I have a model Beer with another model called TastingNotes tied via
foreign key to the Beer table.
models.py
class Beer(models.Model):
beer=models.CharField(max_length=50, core=True)
def __unicode__(self):
return self.beer
class TastingNote(models.Model):
beer=models.ForeignKey(Beer, edit_inline=models.TABULAR,
raw_id_admin=True, num_in_admin=1)
tastingnotes=models.TextField('Tasting notes', core=True)
rating=models.CharField(max_length=1,
choices=RATING_CHOICES,core=True)
def __unicode__(self):
return self.tastingnotes[:15]+"... Rating:"+self.rating
(note that RATING_CHOICES is defined at the top of models.py).
What I would like is to have a field, average_rating, that belongs to
the Beer model that is the average rating for that beer derived from
all the ratings in the TastingNote model. So I could call it like
this: beer.id.average_rating.
Would I do that with a manager class?
class AveRatingManager(models.Manager):
def get_query_set(self):
for y in self.TastingNote.rating:
rating += y
return (rating/self.TastingNote.count())
Any help or insight into this issue would be greatly appreciated. I am
new to both Django and Python but am having great fun learning.
Thanks
H
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---