On Sep 30, 2009, at 1:54 PM, Tim Chase wrote:
>
>> products_ordered = models.ManyToManyField(Product)
>>
>> i don't like it (as i would have to create my own "through" table/
>> class)
>> for saving the recent price, qty, date etc.
>
> I'm not sure what your complaint about the "through" table is --
> is it that you'd have to create it (which you do below), or is it
> that you're looking for some other way to do it?
>
thanks for your fast reply!
My question is more if that is considered to be best practice?
I am sure many others do have similar scenarios here and there.
do you set it up the same way?
are there any caveats to use many-to-many relations?
things like putting more than one many-to-many field in e.g.
"order":
> class Product(Model):
> pass # your code here
class Job(Model)
> class Order(Model):
> products = ManyToMany("Product", through="ProductOrdered")
jobstodo = ManyToMany("Jobs",through="JobsToDo")
>> blow up the Order-Class with all the Details and many
>> ManyToManyFields,ForeignKeyFields
>>
>> or create some Classes that contain foreignKeys references to
>> OrderInstances:
>> e.g.:
>> class ProductOrdered(models.Model):
>> order = models.ForeignKey(Order, related_name=_
>> ("products_ordered"))
>> product = models.ForeignKey(Product,related_name=_
>> ("products_ordered"))
>> qty = models.PositiveIntegerField(_("Quantity"))
>> price_per_piece = models.DecimalField(max_digits=10,
>> decimal_places=3)
>
> because Django offers a "through" attribute for ManyToMany fields:
>
> http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships
>
> that allows you to specify
>
> class Product(Model):
> pass # your code here
> class Order(Model):
> products = ManyToMany("Product", through="ProductOrdered")
> class ProductOrdered(Model):
> pass # your code here
>
> which sounds exactly like what you want to do.
>
> -tim
>
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---