浏览代码

Finished the second part

unknown 3 月之前
父节点
当前提交
812b72a3b8
共有 8 个文件被更改,包括 21 次插入3 次删除
  1. 1 0
      .gitignore
  2. 二进制
      db.sqlite3
  3. 二进制
      mysite/__pycache__/__init__.cpython-313.pyc
  4. 二进制
      mysite/__pycache__/settings.cpython-313.pyc
  5. 二进制
      mysite/__pycache__/urls.cpython-313.pyc
  6. 二进制
      mysite/__pycache__/wsgi.cpython-313.pyc
  7. 5 0
      polls/admin.py
  8. 15 3
      polls/models.py

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 /env
 __pycache__/
+migrations/
 

二进制
db.sqlite3


二进制
mysite/__pycache__/__init__.cpython-313.pyc


二进制
mysite/__pycache__/settings.cpython-313.pyc


二进制
mysite/__pycache__/urls.cpython-313.pyc


二进制
mysite/__pycache__/wsgi.cpython-313.pyc


+ 5 - 0
polls/admin.py

@@ -1,3 +1,8 @@
 from django.contrib import admin
 
+from .models import Question
+
 # Register your models here.
+
+admin.site.register(Question)
+

+ 15 - 3
polls/models.py

@@ -1,4 +1,7 @@
+import datetime
+
 from django.db import models
+from django.utils import timezone
 
 # Create your models here.
 
@@ -6,8 +9,17 @@ 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 Choise(models.Model):
+class Choice(models.Model):
     question = models.ForeignKey(Question, on_delete=models.CASCADE)
-    chouise_text = models.CharField(max_length=200)
-    votes = models.IntegerField(default=0)
+    choice_text = models.CharField(max_length=200)
+    votes = models.IntegerField(default=0)
+
+    def __str__(self):
+        return self.choice_text