class Question(models.Model):
question = models.CharField(max_length=255)
date = models.DateTimeField('Was published')
def __str__(self):
return self.question
def was_published_recently(self):
return timezone.now() - datetime.timedelta(days=1) <= self.date <= timezone.now()
class Answer(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
answer = models.CharField(max_length=255)
vote = models.IntegerField(default=0)
def __str__(self):
return self.answer
{% load static %}
<link rel='stylesheet' type='text/css' href="{% static 'sleep/style.css'%}">
<h2>Questions</h2>
<ul>
{% for q in question_list %}
<li><a href="{% url 'detail' q.id%}">{{ q.question }} </a></li>
{% endfor %}
</ul>
<h2>Category</h2>
<ul>
{% for c in category_list %}
<li><a href="{% url 'members' c.id%}">{{ c.category }} </a></li>
{% endfor %}
</ul>