Ticket #24624: models.py

File models.py, 1.8 KB (added by Scott Sanders, 10 years ago)
Line 
1from django.db import models
2from django.contrib.auth.models import User
3
4
5class Client(models.Model):
6 """ Stores a single client entry """
7 first_name = models.CharField(max_length=50)
8 last_name = models.CharField(max_length=50)
9 street = models.CharField(max_length=100)
10 street_alt = models.CharField(max_length=100, blank=True)
11 city = models.CharField(max_length=50)
12 prov = models.CharField(max_length=2)
13 postal = models.CharField(max_length=12, blank=True)
14 created = models.DateTimeField(auto_now_add=True)
15 updated = models.DateTimeField(auto_now=True)
16
17 class Meta:
18 ordering = ['last_name', 'first_name']
19
20 def get_absolute_url(self):
21 return u'/client/%d' % self.id
22
23 def __unicode__(self):
24 """
25 Returns the client's first and last name
26 :return:
27 """
28 return u"%s %s" % (self.first_name, self.last_name)
29
30
31class ClientPhone(models.Model):
32 client = models.ForeignKey(Client)
33 type = models.CharField(max_length=10)
34 phone = models.CharField(max_length=15)
35
36 def __unicode__(self):
37 return self.phone
38
39
40class ClientEmail(models.Model):
41 client = models.ForeignKey(Client)
42 type = models.CharField(max_length=10)
43 email = models.EmailField()
44 accepts_emails = models.BooleanField(default=False)
45
46 def __unicode__(self):
47 return self.email
48
49
50class ClientNote(models.Model):
51 client = models.ForeignKey(Client)
52 created = models.DateTimeField(auto_now_add=True)
53 note = models.TextField()
54 creator = models.ForeignKey(User)
55
56
57class ClientDiscount(models.Model):
58 client = models.ForeignKey(Client)
59 reason = models.CharField(max_length=10)
60 amount = models.DecimalField(max_digits=4, decimal_places=2)
61 created = models.DateTimeField(auto_now_add=True)
62 creator = models.ForeignKey(User)
Back to Top