(attrs: dict, pk_attr: str, name: str, is_abstract)
| 598 | |
| 599 | @staticmethod |
| 600 | def _parse_custom_pk(attrs: dict, pk_attr: str, name: str, is_abstract) -> tuple[dict, str]: |
| 601 | custom_pk_present = False |
| 602 | for key, value in attrs.items(): |
| 603 | if isinstance(value, Field): |
| 604 | if value.pk: |
| 605 | if custom_pk_present: |
| 606 | raise ConfigurationError( |
| 607 | f"Can't create model {name} with two primary keys," |
| 608 | " only single primary key is supported" |
| 609 | ) |
| 610 | if value.generated and not value.allows_generated: |
| 611 | raise ConfigurationError( |
| 612 | f"Field '{key}' ({value.__class__.__name__}) can't be DB-generated" |
| 613 | ) |
| 614 | custom_pk_present = True |
| 615 | pk_attr = key |
| 616 | |
| 617 | if not custom_pk_present and not is_abstract: |
| 618 | if "id" not in attrs: |
| 619 | attrs = {"id": IntField(primary_key=True), **attrs} |
| 620 | |
| 621 | if not isinstance(attrs["id"], Field) or not attrs["id"].pk: |
| 622 | raise ConfigurationError( |
| 623 | f"Can't create model {name} without explicit primary key if field 'id'" |
| 624 | " already present" |
| 625 | ) |
| 626 | return attrs, pk_attr |
| 627 | |
| 628 | @staticmethod |
| 629 | def _dispatch_fields( |
no test coverage detected