How would I create an expiration date option for new posts that would only show when they are unexpired?
Asked
Active
Viewed 2,745 times
1 Answers
4
In your model you need something like this:
expiration_date = models.DateTimeField()
Then in your views you could access the database like this:
def UnexpiredPosts(request):
unexpired_posts = YourPostModelName.objects.filter(expiration_date__gt = datetime.now())
return render(request, "path_to_template", {'Posts': unexpired_posts})
The template:
<ul>
{% for i in Posts %}
<li>{{ i }}</li>
{% endfor %}
</ul>

Ulfric Storm
- 129
- 2
- 12