Sunday, March 31, 2013

Re: Data Structure - Orders and multiple items

Sorry for the half response...please ignore the previous message.

class order(models.Model): 
    order_id = models.IntegerField(unique=True) 
    customer_id = models.ForeignKey('Customer')
    item_id = models.ForeignKey('Item')
    qty = models.IntegerField()

This will you give the provision to store multiple items to be added against each customer and the quantity of the order against each customer.

-Siddharth



On Mon, Apr 1, 2013 at 9:37 AM, Eric Lovrien <eric.lovrien@gmail.com> wrote:
I am not sure of how or the best way to structure my data in models.py. I would like to have an order and allow multiple items / products to be added to an order. I know I can do a ManyToMany field but not sure how I would connect a qty to that. I am sure there is some simple way of doing this, or a better way to model the data. I know in many ERP systems they have an orders table and then an orders details table. Below is just a quick mock-up of how i was thinking on to do it until I started thinking about the many items and qty to an single order issue came up. Can any one give me some tips on how to accomplish this? 



class Item(models.Model): 
    name = models.CharField(max_length200) 
    description = models.TextField(blank=True) 

    def __unicode__(self): 
         return self.name 

class Customer 
    first_name = models.CharField(max_length=100) 
    last_name = models.CharField(max_length=100) 
    address = models.CharField(max_length=200) 

    def __unicode__(self): 
        return self.name 

class order(models.Model): 
    order = models.IntegerField(unique=True) 
    customer = models.ForeignKey('Customer') 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment