Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How to implement a form to update the quantity?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
enemybass  
View profile  
 More options Oct 1 2012, 11:46 am
From: enemybass <dominikan...@gmail.com>
Date: Mon, 1 Oct 2012 08:46:50 -0700 (PDT)
Local: Mon, Oct 1 2012 11:46 am
Subject: How to implement a form to update the quantity?

Hi. How to implement a form to update the quantity Car? I have no idea how
to do it. Thanks

Code: http://dpaste.com/808558/

or here:

    class Car(models.Model):
        name = models.CharField(max_length=50)
        price = models.DecimalField()    

    class GarageCar(models.Model):
        car = models.ForeignKey('Car')
        garage = models.ForeignKey('Garage')
        quantity = models.IntegerField()

    class Garage(models.Model):
        name = models.CharField("Garage_Name", max_length=30)
        cars = models.ManyToManyField('Car', through='GarageCar',
blank=True, null=True)
        owner = models.ForeignKey(User, related_name='owner_garage',
verbose_name='Owner Garage')

In this way updates the quantity:

    In [2]: c = Car.objects.get(id=1) #here I need car ID

    In [3]: g = Garage.objects.get(owner=1)

    In [4]: q = 33 #here I need data from form

    In [5]: c= GarageCar.objects.filter(car=c, garage=g).update(quantity=q)

views:

    def show(request):
        user = request.user
        garage = Garage.objects.get(owner=user)

        return render_to_response('garage.html', {'garage': garage,
'form':form})

in garage.html:

    {% for item in garage.garagecar_set.all %}
            Car:      {{item.car.name}}
            Price:    {{item.car.price}}
            Quantity: {{item.quantity}}
            ID:       {{item.car.id}}
    {% endfor %}

in forms.py:

    from django import forms

    class QuantityForm(forms.Form):
        q = forms.IntegerField

How to create ORM query to update quantity?

How to display a form field next to each car in template (with button
"Update")?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Baklanov  
View profile  
 More options Oct 1 2012, 2:52 pm
From: Anton Baklanov <antonbakla...@gmail.com>
Date: Mon, 1 Oct 2012 21:52:01 +0300
Local: Mon, Oct 1 2012 2:52 pm
Subject: Re: How to implement a form to update the quantity?

Hi!

You can use something like:

{% for item in garage.garagecar_set.all %}
            Car:      {{item.car.name}}
            Price:    {{item.car.price}}
            Quantity: {{item.quantity}}
            ID:       {{item.car.id}}
            <form action="../update_q/{{item.pk}}/" method="post"/>
              {{form.q}}
              <input type="submit" value="update"/>
            </form>
 {% endfor %}

and view like

def update_q(request, garagecar_id):
    # get garagecar by id here, create form from request, set new value, save()

it to submit forms with ajax, to not reload entire page every time.

P.S.

it looks you are implementing Many-to-Many-Through relation. Django
has support for it out of the box
https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-...

--
Regards,
Anton Baklanov


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Baklanov  
View profile  
 More options Oct 1 2012, 2:55 pm
From: Anton Baklanov <antonbakla...@gmail.com>
Date: Mon, 1 Oct 2012 21:55:15 +0300
Local: Mon, Oct 1 2012 2:55 pm
Subject: Re: How to implement a form to update the quantity?

it *is good idea* to submit...

missed some words, lol

On Mon, Oct 1, 2012 at 9:52 PM, Anton Baklanov <antonbakla...@gmail.com>wrote:

> it to submit forms with ajax, to not reload entire page every time.

--
Regards,
Anton Baklanov

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Domi nika  
View profile  
 More options Oct 10 2012, 7:27 am
From: Domi nika <dominikan...@gmail.com>
Date: Wed, 10 Oct 2012 13:27:02 +0200
Local: Wed, Oct 10 2012 7:27 am
Subject: Re: How to implement a form to update the quantity?

Thanks. Is it possible to display multiple form in loop?

2012/10/1 Anton Baklanov <antonbakla...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions Older topic »