-
Notifications
You must be signed in to change notification settings - Fork 343
/
models.py
37 lines (28 loc) · 965 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from django.db import models
from django.contrib.auth.models import User
import numpy as np
class Wine(models.Model):
name = models.CharField(max_length=200)
def average_rating(self):
all_ratings = map(lambda x: x.rating, self.review_set.all())
return np.mean(all_ratings)
def __unicode__(self):
return self.name
class Review(models.Model):
RATING_CHOICES = (
(1, '1'),
(2, '2'),
(3, '3'),
(4, '4'),
(5, '5'),
)
wine = models.ForeignKey(Wine)
pub_date = models.DateTimeField('date published')
user_name = models.CharField(max_length=100)
comment = models.CharField(max_length=200)
rating = models.IntegerField(choices=RATING_CHOICES)
class Cluster(models.Model):
name = models.CharField(max_length=100)
users = models.ManyToManyField(User)
def get_members(self):
return "\n".join([u.username for u in self.users.all()])