From 33f124ba84a2ed9acc0f34fef1112882498e6551 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 19 Oct 2010 15:02:45 +0200 Subject: [PATCH] tickets: Add a (virtual) Booking.price property. --- tickets/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tickets/models.py b/tickets/models.py index f022e6f..5c56b0a 100644 --- a/tickets/models.py +++ b/tickets/models.py @@ -1,3 +1,5 @@ +# coding=utf-8 + from django.db import models # Create your models here. @@ -9,6 +11,8 @@ SHOW_CHOICES = [ ("vrijdag", "vrijdag 17 december, 20:00") TICKETS_CHOICES = [ (n, n) for n in range(1, 6)] +TICKET_PRICE=10 + class Booking(models.Model): created = models.DateTimeField(auto_now_add=True, editable=False, verbose_name="Datum") name = models.CharField(max_length=100, verbose_name="Naam") @@ -18,3 +22,7 @@ class Booking(models.Model): tickets = models.IntegerField(choices=TICKETS_CHOICES, verbose_name="Aantal kaarten") show = models.CharField(max_length=50, choices=SHOW_CHOICES, verbose_name="Voorstelling") payment = models.DateTimeField(blank=True, null=True, verbose_name="Betaling vewerkt op") + + def _get_price(self): + return self.tickets * TICKET_PRICE + price = property(_get_price) -- 2.30.2