Writing you first Django app problem

40 views
Skip to first unread message

rbarh...@gmail.com

unread,
Aug 26, 2020, 1:05:36 PM8/26/20
to Django users
Looking at my post it seems that there is not much to go on in terms of understanding my problem.  So, let me try to provide more detail.

I am in part 2 of the tutorial working with "models" (sqlite) and have written this code into "polls/models.py:

~~~
from django.db import models
from django.utils import timezone
import datetime

# 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

~~~
The indents are correct, just not shown in the markdown.  

This is the shell command that brought the error:

 Question.objects.get(pub_date_year=current_year) 

Something is wrong with defining "current_year" and making it work.  Can anyone see the problem?

Ogunsanya Opeyemi

unread,
Aug 26, 2020, 3:12:34 PM8/26/20
to django...@googlegroups.com
You have not defined current_year
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f326a70c-50a4-4f0a-a2d5-69e205ea0933n%40googlegroups.com.


--
OGUNSANYA OPEYEMI

rbarh...@gmail.com

unread,
Aug 27, 2020, 7:56:17 PM8/27/20
to Django users
thank you, but that does not seem to be the problem.  Maixm below solved the problem if you are interested.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.


--
OGUNSANYA OPEYEMI

Reply all
Reply to author
Forward
0 new messages