Hi!

I need an order form that will handle the orders for X number of  
students and Y number of products. I have a working solution that  
creates a <form>..</form> for every product and submits it on  
onchange, but I was wondering if there was more of a "django" way to  
do this.

I would like my form to look like this:

--------------
Student name    | Product 1: <quantity> | Product 2: <quantity> | sum:  
price*quantity etc
Student name    | Product 1: <quantity> | Product 2: <quantity> | sum:  
price*quantity etc
Student name    | Product 1: <quantity> | Product 2: <quantity> | sum:  
price*quantity etc
Student name    | Product 1: <quantity> | Product 2: <quantity> | sum:  
price*quantity etc
Student name    | Product 1: <quantity> | Product 2: <quantity> | sum:  
price*quantity etc
                                | total q of this product  | total q of this 
product  | sum:  
total price
--------------

The school administrator need to add/remove products and hey should  
be able to tab through the form(not hitting any save button for every  
field.)


My models:

class Student(models.Model):
        first_name = models.CharField(maxlength=30)
        last_name = models.CharField(maxlength=30)

class Product(models.Model):
        name = models.CharField(maxlength=20)
        description = models.TextField()
        price = models.DecimalField(max_digits=5, decimal_places=2)

class Order(models.Model):
        student = models.ForeignKey(Student)
        product = models.ForeignKey(Product)
        quantity = models.IntegerField()



My template code:

{% for student in students %}
        {{ student.first_name }} {{ student.last_name }}

        {% for product in products %}
                {{ product.name }}
                <form> <input type="hidden" product.id and student.id />
                <input type="text" value="{% order-quantity student.id 
product.id  
%}" onchange="run ajax query to place the order"/>
                </form>
        {% endfor %}
{% endfor %}

order-quantity is a custom template tag with this logic: orders =  
student.order_set.filter(product=product) and then returns the  
quantity from the first order object.


Any help would be greatly appreciated!

--
Knut Ivar Nesheim




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to