Link LineItem to an Invoice via some foreign key or related manager #1958
Labels
discussion
The premise or details of this issue is open for discussion
Milestone
Is your request related to a problem? Please describe.
Recently I've been trying to access the
LineItem
objects that are tied to a particularInvoice
. I would like to do this offline (i.e. through the database/Django models, instead of calling the Stripe API directly or usingapi_list
). However, there does not seem to be anyinvoice_id
property or some join table betweenInvoice
andLineItem
.In Stripe's own JSON response from their invoice API, the lines property encapsulates this relationship. On an
Invoice
response from Stripe, there is an array ofLineItem
objects that clearly tie to the givenInvoice
. But in the djstripe models, nothing directly conveys "given thisInvoice
, these are theLineItems
"To make matters more complicated,
LineItem
can have either an associatedInvoiceItem
(theinvoice_item_id
column) or aSubscription
(subscription_id
column), and doesn't always have both available.InvoiceItem
clearly links back to anInvoice
through theinvoice_id
, butSubscription
does not directly link to a givenInvoice
. So the subscription-typeLineItem
isn't covered well for this problem.Describe the solution you'd like
Either a
lines
Field/ many-to-one manager/join table on theInvoice
item relating it directly toLineItem
, or aninvoice
ForeignKey field onLineItem
itself. Just generally some direct relation in the database between aInvoice
and aLineItem
Additional context
The text was updated successfully, but these errors were encountered: