File tree Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 1+ # Generated by Django 3.1.14 on 2023-10-18 07:18
2+
3+ from django .db import migrations , models
4+ import django .utils .timezone
5+
6+
7+ class Migration (migrations .Migration ):
8+
9+ dependencies = [
10+ ('polls' , '0001_initial' ),
11+ ]
12+
13+ operations = [
14+ migrations .AddField (
15+ model_name = 'choice' ,
16+ name = 'created_at' ,
17+ field = models .DateTimeField (auto_now_add = True , default = django .utils .timezone .now ),
18+ preserve_default = False ,
19+ ),
20+ migrations .AddField (
21+ model_name = 'choice' ,
22+ name = 'updated_at' ,
23+ field = models .DateTimeField (auto_now = True ),
24+ ),
25+ migrations .AddField (
26+ model_name = 'poll' ,
27+ name = 'created_at' ,
28+ field = models .DateTimeField (auto_now_add = True , default = django .utils .timezone .now ),
29+ preserve_default = False ,
30+ ),
31+ migrations .AddField (
32+ model_name = 'vote' ,
33+ name = 'created_at' ,
34+ field = models .DateTimeField (auto_now_add = True , default = django .utils .timezone .now ),
35+ preserve_default = False ,
36+ ),
37+ migrations .AddField (
38+ model_name = 'vote' ,
39+ name = 'updated_at' ,
40+ field = models .DateTimeField (auto_now = True ),
41+ ),
42+ ]
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ class Poll(models.Model):
99 text = models .TextField ()
1010 pub_date = models .DateTimeField (default = timezone .now )
1111 active = models .BooleanField (default = True )
12+ created_at = models .DateTimeField (auto_now_add = True )
1213
1314 def user_can_vote (self , user ):
1415 """
@@ -50,6 +51,8 @@ def __str__(self):
5051class Choice (models .Model ):
5152 poll = models .ForeignKey (Poll , on_delete = models .CASCADE )
5253 choice_text = models .CharField (max_length = 255 )
54+ created_at = models .DateTimeField (auto_now_add = True )
55+ updated_at = models .DateTimeField (auto_now = True )
5356
5457 @property
5558 def get_vote_count (self ):
@@ -63,6 +66,8 @@ class Vote(models.Model):
6366 user = models .ForeignKey (User , on_delete = models .CASCADE )
6467 poll = models .ForeignKey (Poll , on_delete = models .CASCADE )
6568 choice = models .ForeignKey (Choice , on_delete = models .CASCADE )
69+ created_at = models .DateTimeField (auto_now_add = True )
70+ updated_at = models .DateTimeField (auto_now = True )
6671
6772 def __str__ (self ):
6873 return f'{ self .poll .text [:15 ]} - { self .choice .choice_text [:15 ]} - { self .user .username } '
Original file line number Diff line number Diff line change 1818 {% if poll.active %}
1919 < h3 class ="mt-3 mb-3 text-center "> Result for: {{ poll.text }}</ h3 >
2020 {% else %}
21- < h3 class ="mt-3 mb-3 text-center "> "{{ poll.text }}" Has Ended Polling !</ h3 >
21+ < h3 class ="mt-3 mb-3 text-center "> "{{ poll.text }}" Has Ended Polling!</ h3 >
2222 {% endif %}
2323 < h3 class ="mb-2 text-center "> Total: {{ poll.get_vote_count }} votes</ h3 >
2424 <!-- progress bar -->
You can’t perform that action at this time.
0 commit comments