Friday, July 6, 2012

Re: ForeignKey problem

On Fri, 6 Jul 2012 07:23:44 -0700 (PDT), Soviet <soviet1337@gmail.com>
declaimed the following in gmane.comp.python.django.user:

>
>
> > You don't. You get all wheel objects and count them.
> >
>
> I don't understand. It's the same wheel added four times, not four
> different wheels.
>

No... it is four INSTANCES (or if you prefer, COPIES) of an
identical wheel.

The description of the wheel would be a record in one table, but
each individual instance would be a second table with a foreign key
reference to the applicable description. This second table may also have
a foreign key reference to something that identifies what that instance
of the wheel is connected to (making a many-to-many from "something" to
"description" using the individual wheel table as the intersect
("through") table).

About the only place I can see maintaining a count would be
inventory systems. Say a tire dealer:

Tire(*ID*, maker, model, size, number-in-stock, reorder-at)

but as soon as a tire is sold you need to link it to receipt (for
warranty purposes)

Receipt(*ID*, customer, date, vehicle, mileage)

ReceiptDetail(*ID*, /receiptID/, /tireID/, tire-serial-number)

Selling a set of tires will decrement Tire.number-in-stock by the
number of tires sold, and will create a ReceiptDetail for each tire sold
in that transaction. (note that I'm not tracking the tire serial number
until it is sold... The tire maker likely tracked the serial number to
the dealer, but the dealer just shelves the stack until they transfer it
to someone else).

To know how many of a tire type were sold on a receipt requires
running a count of the receiptdetail where tireID =
the-desired-tire-type.

The inventory system doesn't need to know who bought any particular
tire, it just needs to be able to compare the number-in-stock to the
reorder-at value in order to generate an order for more tires.






--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment