Django, making a page activate for a fixed time

Posted by Hellnar on Stack Overflow See other posts from Stack Overflow or by Hellnar
Published on 2010-01-24T18:03:24Z Indexed on 2010/05/03 11:08 UTC
Read the original article Hit count: 415

Greetings I am hacking Django and trying to test something such as:

Like woot.com , I want to sell "an item per day", so only one item will be available for that day (say the default www.mysite.com will be redirected to that item),

Assume my urls for calling these items will be such: www.mysite.com/item/<number>

my model for item:

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()

And my view for rendering this:

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

What would be the efficient and clever model & templete for achieving this ?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models