schema.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from djstripe.models import Price, Product, Subscription, SubscriptionItem
  2. from ninja import ModelSchema
  3. from glitchtip.schema import CamelSchema
  4. class PriceIDSchema(CamelSchema):
  5. price: str
  6. class SubscriptionIn(PriceIDSchema):
  7. organization: int
  8. class ProductSchema(CamelSchema, ModelSchema):
  9. class Meta:
  10. model = Product
  11. fields = ["id", "name", "description", "type", "metadata"]
  12. class PriceSchema(CamelSchema, ModelSchema):
  13. product: ProductSchema
  14. class Meta:
  15. model = Price
  16. fields = [
  17. "id",
  18. "nickname",
  19. "currency",
  20. "unit_amount",
  21. # "human_readable_price",
  22. "metadata",
  23. "product",
  24. ]
  25. class SubscriptionItemSchema(CamelSchema, ModelSchema):
  26. price: PriceSchema
  27. class Meta:
  28. model = SubscriptionItem
  29. fields = ["id", "price"]
  30. class SubscriptionSchema(CamelSchema, ModelSchema):
  31. items: list[SubscriptionItemSchema]
  32. class Meta:
  33. model = Subscription
  34. exclude = ["default_tax_rates"]
  35. class CreateSubscriptionResponse(SubscriptionIn):
  36. subscription: SubscriptionSchema
  37. class ProductPriceSchema(CamelSchema, ModelSchema):
  38. prices: list[PriceSchema]
  39. class Meta:
  40. model = Product
  41. fields = ["id", "name", "description", "type", "metadata"]