PageRenderTime 143ms CodeModel.GetById 60ms app.highlight 18ms RepoModel.GetById 62ms app.codeStats 1ms

/recometproject/recomet/models.py

https://code.google.com/p/recomet/
Python | 164 lines | 106 code | 28 blank | 30 comment | 0 complexity | e8fa613a7172e515462ebcb856670ef8 MD5 | raw file
  1# -*- coding: utf-8 -*-
  2
  3from django.db import models
  4import datetime
  5
  6class Cuisine(models.Model):
  7    cuisine = models.CharField(max_length=28)
  8    def __unicode__(self):
  9        return self.cuisine
 10    
 11#Table Recommender_Rule
 12class Recommender_rule(models.Model):
 13    rule = models.TextField()
 14    def __unicode__(self):
 15        return self.rule
 16
 17#Table many to many by atribute_group.
 18class Atribute_Group(models.Model):
 19   # id_atribute_group = models.AutoField(primary_key=True)
 20    group = models.CharField(max_length=32, null=True)
 21    def __unicode__(self):
 22        return self.group
 23    
 24#Table atribute
 25class Atribute(models.Model):
 26    #id_atribute = models.AutoField(max_length=10, primary_key=True) 
 27    group = models.ForeignKey(Atribute_Group) 
 28    value = models.CharField(max_length=32)
 29    def __unicode__(self):
 30        return self.value
 31    
 32#Table restaurantChain.
 33class RestaurantChain(models.Model):
 34    #id_chain =  models.AutoField(max_length=10, primary_key=True)
 35    is_international = models.BooleanField()
 36    name = models.CharField(max_length=128)
 37    speciality = models.CharField(max_length=128)
 38    year_founded = models.PositiveSmallIntegerField(null=True)
 39    locations_worldwide = models.PositiveSmallIntegerField(null=True)
 40    
 41    def __unicode__(self):
 42        return self.name
 43
 44class Item(models.Model):
 45#    id_item = models.OneToOneField(Restaurant) #IntegerField(max_length=10) 
 46    recommender_rule = models.ForeignKey(Recommender_rule, null=True)
 47      
 48      
 49#Table for restaurant.
 50class Restaurant(models.Model):
 51   #id_item = models.AutoField(max_length=10, primary_key=True)
 52    item = models.OneToOneField(Item, primary_key=True)
 53    atribute = models.ManyToManyField(Atribute)
 54    cuisine =  models.ManyToManyField(Cuisine)
 55    name = models.CharField(max_length=255)
 56    address = models.TextField(max_length=512, null=True)
 57    description = models.TextField()
 58    needs_reservation = models.BooleanField()
 59    price_range = models.CharField(max_length=64)
 60    url = models.URLField(max_length=512, null=True)
 61    phone = models.CharField(max_length=18, null=True)
 62    hours = models.TextField(max_length=128, null=True)
 63    slug_name = models.SlugField(max_length=18, null=True)
 64    chain = models.ForeignKey(RestaurantChain, null=True) 
 65    lat = models.DecimalField(max_digits=8, decimal_places=5, null=True) 
 66    alt = models.DecimalField(max_digits=8, decimal_places=5, null=True)
 67    pub_date = models.DateTimeField('date published')
 68
 69    def __unicode__(self):
 70        return self.name
 71        
 72  
 73
 74#------------------------------------------------------------#
 75# MODELO DE USUARIO                                          #
 76#------------------------------------------------------------#
 77#Table container.
 78class Container(models.Model):
 79#    id_container = models.AutoField(max_length=10, primary_key=True)
 80    container_name = models.CharField(max_length=64) #Entero en el modelo
 81    is_public = models.BooleanField()
 82    def __unicode__(self):
 83        return self.container_name
 84
 85
 86#Table rating_dimension.
 87class Rating_Dimension(models.Model):
 88    #id_dimension = models.AutoField(max_length=10, primary_key=True)
 89    dimension_name = models.CharField(max_length=64)
 90    priority = models.IntegerField(null=True)
 91    
 92    def __unicode__(self):
 93        return self.dimension_name
 94
 95#Table user.
 96class Users(models.Model):
 97#    id_user =  models.AutoField(max_length=10, primary_key=True)
 98    username = models.CharField(max_length=20)
 99    container = models.ManyToManyField(Container, through='Container_User')
100    ratings = models.ManyToManyField(Item, through='Rating', related_name='ratings')
101    reviews = models.ManyToManyField(Item, through='Review', related_name='reviews')
102    
103    def __unicode__(self):
104        return self.username
105    
106LANG = (
107    ('es', 'EspaƄol'),
108    ('en', 'English'),
109    ('fr', 'French'),
110    ('jp', 'Japanese'),
111   ) 
112    
113#Table Review.
114class Review(models.Model):
115    item_reviewed = models.ForeignKey(Item)
116    id_user = models.ForeignKey(Users) 
117    title = models.CharField(max_length=128)
118    review = models.TextField()
119    status = models.PositiveSmallIntegerField(null=True)
120    review_time = models.DateTimeField()
121    helpful_yes = models.IntegerField(max_length=128)
122    helpful_no = models.IntegerField(max_length=128)
123    language = models.CharField(max_length=2, choices=LANG)
124    
125    def __unicode__(self):
126        return self.title
127    
128#Table user rating.
129class Rating(models.Model):
130    id_item =  models.ForeignKey(Item) 
131    id_user = models.ForeignKey(Users) 
132    id_dimension = models.ForeignKey(Rating_Dimension)
133    date = models.DateTimeField()
134    rating = models.PositiveSmallIntegerField()
135    def __unicode__(self):
136        return self.rating
137    
138#Table of Friends for an user. Assigns a related name for the relationship.
139class Friends(models.Model):
140    id_user = models.ForeignKey(Users, related_name='user')
141    id_friend = models.ForeignKey(Users, related_name='friends') #models.IntegerField(max_length=10)
142    time_added = models.DateTimeField(null=True)
143    
144    def __unicode__(self):
145        return self.time_added
146
147#-----------------------------------------------------------------------------
148#CONTENEDORES
149#-----------------------------------------------------------------------------  
150#Table user container.
151class Container_User(models.Model):
152    id_container =  models.ForeignKey(Container) 
153    id_user = models.ForeignKey(Users) 
154    id_itemid_item = models.ForeignKey(Item)
155
156#Table Tag.
157class Tag(models.Model):
158#   id_tag = models.AutoField(max_length=10, primary_key=True) 
159    tag = models.CharField(max_length=18)
160    id_item = models.ForeignKey(Item) 
161    
162    def __unicode__(self):
163        return self.tag
164# Create your models here.