问候我正在破解 Django 并尝试测试以下内容:
像woot.com一样,我想出售“每天一件商品”,因此当天只有一件商品可用(假设默认 www.mysite.com 将被重定向到该商品),
假设我调用这些项目的网址是这样的:www.mysite.com/item/<number>
我的项目模型:
class Item(models.Model):
item_name = models.CharField(max_length=30)
price = models.FloatField()
content = models.TextField() #keeps all the html content
start_time = models.DateTimeField()
end_time = models.DateTimeField()
我对渲染的看法:
def results(request, item_id):
item = get_object_or_404(Item, pk=item_id)
now = datetime.now()
if item.start_time > now:
#render and return some "not started yet" error templete
elif item.end_time < now:
#render and return some "item selling ended" error templete
else:
# render the real templete for selling this item
实现这一目标的有效和聪明的模型和模板是什么?