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

15 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 12:42 +0000

1from typing import TYPE_CHECKING 

2from uuid import UUID 

3 

4from sqlalchemy import ForeignKey, UniqueConstraint, Uuid 

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

6 

7from polar.custom_field.attachment import AttachedCustomFieldMixin 

8from polar.kit.db.models import RecordModel 

9 

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

11 from polar.models import Product 

12 

13 

14class ProductCustomField(AttachedCustomFieldMixin, RecordModel): 

15 __tablename__ = "product_custom_fields" 

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

17 

18 product_id: Mapped[UUID] = mapped_column( 

19 Uuid, 

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

21 primary_key=True, 

22 ) 

23 

24 @declared_attr 

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

26 return relationship( 

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

28 )