On 1 April 2013 15:07, 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?
Use an intermediary model as described in the docs:
https://docs.djangoproject.com/en/1.5/topics/db/models/#extra-fields-on-many-to-many-relationships
This will be your best bet I think.
L.
>
>
>
> 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.
>
>
--
The new creativity is pointing, not making. Likewise, in the future,
the best writers will be the best information managers.
http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith
--
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment