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 received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Zpek_KYrEsAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to