Django form - keep some POST data -
i writing small django internet store , have encountered problem. namely, print list of products (i need pruduct id) , form buy them on same page.
def order(request): if request.method == 'post': form = orderform(request.post) if form.is_valid(): # post data processing return httpresponseredirect('/cart/') else: form = orderform() # here use product_id post generate products # have such id return render(request, 'order.html', { 'form': form, 'products': products, })
but when wrongly submit form, orderform() called , lose id. hints how solve problem (maybe keep somewhere id)?
edit: store used rent products on given time , adding product cart means create new object rent store information when product has been reserved user
model:
class rent(models.model): product = models.foreignkey(product) paid = models.booleanfield() begin_date = models.datefield(auto_now=false) end_date = models.datefield(auto_now=false) begin_hour = models.integerfield(max_length=2, default=00) end_hour = models.integerfield(max_length=2, default=24)
and orderform
class orderform(forms.form): begin_date = forms.datefield(label='date', required=true, widget=extras.widgets.selectdatewidget(years=range(2013, 2015))) end_date = forms.datefield(required=true, initial=datetime.date.today, widget=extras.widgets.selectdatewidget(years=range(2013, 2015))) begin_hour = forms.choicefield(required=true, choices=((str(x), x) x in range(0, 25))) end_hour = forms.choicefield(required=true, choices=(((str(x)), x) x in range(0, 25)))
Comments
Post a Comment