Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango form - keep some POST data
    primarykey
    data
    text
    <p>I am writing small django internet store and I have encountered a problem. Namely, I would like print list of the products (I need pruduct id) and also some form to buy them on the same page.</p> <pre><code>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 I would like to also use product_id from POST to generate products # that have such id return render(request, 'order.html', { 'form': form, 'products': products, }) </code></pre> <p>But when I wrongly submit form, OrderForm() is called and then I lose my id. Any hints how to solve this problem (maybe keep somewhere that id)? </p> <p>Edit: my store is used to rent some products on given time and adding product to cart means that I create new object rent that store information when product has been reserved by user</p> <p>Model:</p> <pre><code>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) </code></pre> <p>And OrderForm</p> <pre><code>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) for x in range(0, 25))) end_hour = forms.ChoiceField(required=True, choices=(((str(x)), x) for x in range(0, 25))) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload