Coverage for polar/models/product_custom_field.py: 88%

15 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 15:52 +0000

1from typing import TYPE_CHECKING 1ab

2from uuid import UUID 1ab

3 

4from sqlalchemy import ForeignKey, UniqueConstraint, Uuid 1ab

5from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship 1ab

6 

7from polar.custom_field.attachment import AttachedCustomFieldMixin 1ab

8from polar.kit.db.models import RecordModel 1ab

9 

10if TYPE_CHECKING: 10 ↛ 11line 10 didn't jump to line 11 because the condition on line 10 was never true1ab

11 from polar.models import Product 

12 

13 

14class ProductCustomField(AttachedCustomFieldMixin, RecordModel): 1ab

15 __tablename__ = "product_custom_fields" 1ab

16 __table_args__ = (UniqueConstraint("product_id", "order"),) 1ab

17 

18 product_id: Mapped[UUID] = mapped_column( 1ab

19 Uuid, 

20 ForeignKey("products.id", ondelete="cascade"), 

21 primary_key=True, 

22 ) 

23 

24 @declared_attr 1ab

25 def product(cls) -> Mapped["Product"]: 1ab

26 return relationship( 1ab

27 "Product", lazy="raise", back_populates="attached_custom_fields" 

28 )