Example #1
0
def edit_auction(request,id):
    auction=Auction.objects.get(id=id)
    form=AuctionForm(instance=auction)
    if request.method=='POST':
        data = request.POST.copy()      
        form=AuctionForm(data,file_data)
        if form.is_valid():
            auction.time_left=data['time_left']
            auction.price=data['price']
            auction.product=data['product']
            auction.time_delta=data['time_delta']
            auction.save()
            return HttpResponseRedirect('/admin/auctions/')
    return render_to_response('admin/auction_form.html',{'auction_form':form,'edit':True,'id':id},context_instance=RequestContext(request))
Example #2
0
def add_auction(request):
    form=AuctionForm()
    if request.method=='POST':
        data = request.POST.copy()
        form=AuctionForm(data)
        if form.is_valid():
            auction=Auction(time_left=data['time_left'], product=Product.objects.get(id=int(data['product'])), price=data['price'], time_delta=data['time_delta'], is_active=True)
            prod=Product.objects.get(id=int(data['product']))
            if prod.number > 0:
                prod.number -= 1
                prod.save()
            else:
                pass
            auction.save()
            return HttpResponseRedirect('/admin/auctions/')
    return render_to_response('admin/auction_form.html',{'auction_form':form,'edit':False},context_instance=RequestContext(request))