Ticket #4697: models.py

File models.py, 2.4 KB (added by anonymous, 17 years ago)

models.py

Line 
1from django.db import models
2import datetime
3
4class Survey(models.Model):
5 name = models.CharField(maxlength=20)
6 description= models.CharField(maxlength=200)
7 start_date=models.DateField("Effective from")
8 end_date=models.DateField("Effective to")
9
10 def __str__(self):
11 return self.name
12 def is_effective(self):
13 if start_date<datetime.date.today()<end_date:
14 return True
15 else:
16 return False
17 class Admin:
18 search_fields = ('name','description')
19 list_display = ('name', 'start_date','end_date')
20 list_filter = ['name', 'start_date','end_date']
21
22class Poll(models.Model):
23 survey=models.ForeignKey(Survey,edit_inline=models.TABULAR)
24 title=models.CharField(maxlength=20,core=True)
25 question = models.CharField(maxlength=200)
26 pub_date = models.DateField('date published',auto_now=True)
27
28 def __str__(self):
29 return self.title
30 def was_published_today(self):
31 return self.pub_date.date() == datetime.date.today()
32 class Admin:
33 search_fields = ['title','question']
34 list_display = ('title','pub_date')
35 list_filter = ['pub_date']
36
37class Choice(models.Model):
38 poll = models.ForeignKey(Poll, edit_inline=models.STACKED,
39 min_num_in_admin=0,max_num_in_admin=10,
40 num_extra_on_change=1)
41 choice = models.CharField(maxlength=200,core=True)
42 votes = models.IntegerField(core=True)
43
44 def __str__(self):
45 return self.choice
46# class Admin:
47# pass
48
49class Interviewee(models.Model):
50 firstname = models.CharField(maxlength=40,core=True)
51 lastname = models.CharField(maxlength=40,core=True)
52 IP = models.IPAddressField()
53 comments = models.CharField(maxlength=200,blank=True)
54
55 def __str__(self):
56 return self.firstname +" "+ self.lastname
57 class Admin:
58 search_fields =('firstname','lastname')
59 list_display = ('firstname','lastname')
60 list_filter = ('firstname','lastname')
61
62class Interview(models.Model):
63 choice = models.ManyToManyField(Choice)
64 interviewee= models.ForeignKey(Interviewee,edit_inline=models.STACKED,
65 min_num_in_admin=0,max_num_in_admin=10,
66 num_in_admin=1, num_extra_on_change=1)
67 title = models.CharField(maxlength=200,core=True)
68
69 def __str__(self):
70 return str(self.title)
71 class Admin:
72 pass
73
Back to Top