Sie sind auf Seite 1von 1

12/6/2014 source.sphene.net/svn/sphene/frameworkcomparison/django/barsite/barcrud/models.

py
http://source.sphene.net/svn/sphene/frameworkcomparison/django/barsite/barcrud/models.py 1/1
from django.db import models
from django.db.models import permalink
from django.contrib.auth.models import User
from datetime import datetime
# Create your models here.
WIFI_CHOICES = (
( 'y', 'yes', ),
( 'n', 'no', ),
( 'p', 'paid', ),
)
class Bar(models.Model):
name = models.CharField(max_length=250)
location = models.CharField(max_length=250)
wifi = models.CharField(max_length=1, choices = WIFI_CHOICES)
creationdate = models.DateTimeField()
editdate = models.DateTimeField()
lasteditor = models.ForeignKey(User)
def save(self):
"""
Saves this bar - callers have to set 'lasteditor' by hand tough !
"""
if not self.id:
self.creationdate = datetime.today()
self.editdate = datetime.today()
return super(Bar, self).save()
@permalink
def get_absolute_url(self):
return ('barcrud.views.details', (), { 'bar_id': self.id })
class Meta:
ordering = ['name']
class Beer(models.Model):
name = models.CharField(max_length = 250)
class Admin:
pass
class BarBeer(models.Model):
bar = models.ForeignKey(Bar)
beer = models.ForeignKey(Beer)
class Comment(models.Model):
bar = models.ForeignKey(Bar)
author = models.ForeignKey(User)
date = models.DateTimeField()
comment = models.TextField()
def save(self):
self.date = datetime.today()
return super(Comment, self).save()
class Meta:
ordering = [ '-date' ]

Das könnte Ihnen auch gefallen