From 80f1d1ac95a746a17e3d9eb50fa73fdec68f5e39 Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Fri, 9 Sep 2022 08:06:49 +0530 Subject: [PATCH] models and funcs --- LCAdmin/db.sqlite3 | Bin 131072 -> 143360 bytes LCAdmin/polls/migrations/0001_initial.py | 52 +++++++++++++++++++++++ LCAdmin/polls/models.py | 21 ++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 LCAdmin/polls/migrations/0001_initial.py diff --git a/LCAdmin/db.sqlite3 b/LCAdmin/db.sqlite3 index 28bcae5040fdcf664083dde31844218b62234601..afe97ac295e17bd2fb774f9449c62fb9fe5ecbc2 100644 GIT binary patch delta 1744 zcmaKtZ%i9?7{`Cl-Icp?y*@2v>q=?+qtHRa7^Q_x$QFjIS(Y`hEf~~fLZLTW2ZgPL zZN7n)_Zy*(lcI{inRp!vZNYA%YyV(aWeK6 z%Th_n@yB~?R;%=f^qq8H`b2tHx*{nBrC(ZhaL^7$JLwJ%I^o~u`Sff>QPpX00|x;x zc;c~h&IvbQKrBer?i^aEoA@^`3dN?o;W!Wwox+G|pWS zx6Fe=R6M|b2DeJP55aXPJ$w=FGUmYs-g%}AluRCC;4R%e3#2ib-Wd$CCy1hdgG+tc_|&Xyy#0);mf@4pp|L0(8+tkxrGDc{Kke|R5`LQBbp*Pk z>Q6V3l`mxTubzRX=7q(ni9|dr`)N65Q*$yM86Be|&%|QE(&I^ZgJJ3)me!|XoaYE( zmkP=`c3H9X^3Kr!C_SlkLcXB4)UUhR{V|bJFU-EF-l_1u&~~7;BKPRX;pnqfx&O1* zPe(_LnE#|YRBaS>y5J>ygm(r4@UpzkExqRU*8cx;O2_iHBhV*SWYpa0TAI(w89z;> zv+|65uI9`hYUod=QZp)&S7u?S)#!hIV-|KZ!TKVs|LuEo!=@hZZ*aCo0Z$YB5x>CO zcmuEDDqh6X1!V-=>;gxe9<4}qL{y!3y0nxou(Wy?mO`(ub9I251UHNJg*(_E1dg;0 zjVI&T_6$wS=Lf@~aJVbfuO8Y1;;Dh2@ZR3=zP|nY%TE;s9}xTnAK-0u`$q__%R@Ul zEsTk{1@l-^rkOJrB`^_>U>=#z(z(UyWcfdy!7YM+;uii|w68ow(L^}b3=GSf&Hn(Z CN&e0N delta 424 zcmZp8z|qjaF+o~To`Hcu0f=G1YNC!Yqx{B%`TQKhyg)%A?tsbc0;(GuRk$|?NN;2j zUm#MNjo#4et#%h*^v zozaI;Zu?#rMk{6}#s?c4?=Wt^>d6?w$aryL=b5J4dNc0c?&iVR&&bHN unQ_8@`9%u^fN0YK76Ab^{w@aoxBNHxPx0^JpU>a5v9XMQd)Il!G6MjdIDMD^ diff --git a/LCAdmin/polls/migrations/0001_initial.py b/LCAdmin/polls/migrations/0001_initial.py new file mode 100644 index 0000000..555a29f --- /dev/null +++ b/LCAdmin/polls/migrations/0001_initial.py @@ -0,0 +1,52 @@ +# Generated by Django 4.1 on 2022-09-09 02:24 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Question", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("question_text", models.CharField(max_length=200)), + ("pub_date", models.DateTimeField(verbose_name="date published")), + ], + ), + migrations.CreateModel( + name="Choice", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("choice_text", models.CharField(max_length=200)), + ("votes", models.IntegerField(default=0)), + ( + "question", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="polls.question" + ), + ), + ], + ), + ] diff --git a/LCAdmin/polls/models.py b/LCAdmin/polls/models.py index 71a8362..416d357 100644 --- a/LCAdmin/polls/models.py +++ b/LCAdmin/polls/models.py @@ -1,3 +1,22 @@ +import datetime from django.db import models +from django.utils import timezone -# Create your models here. +class Question(models.Model): + question_text = models.CharField(max_length=200) + pub_date = models.DateTimeField('date published') + + def __str__(self): + return self.question_text + + def was_published_recently(self): + return self.pub_date >= timezone.now() - datetime.timedelta(days=1) + + +class Choice(models.Model): + question = models.ForeignKey(Question, on_delete=models.CASCADE) + choice_text = models.CharField(max_length=200) + votes = models.IntegerField(default=0) + + def __str__(self): + return self.choice_text \ No newline at end of file