onconova.terminology.fields
CodedConceptModel
module-attribute
¶
DescendsFrom
¶
Bases: Lookup
lookup_name
class-attribute
instance-attribute
¶
as_sql(compiler, connection)
¶
Converts the lookup into SQL.
This method is overridden from the Lookup class to create a recursive CTE query that traverses the parent-child relationships of the CodedConceptField.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Any
|
The SQLCompiler instance. |
required |
|
Any
|
The database connection. |
required |
Returns:
Type | Description |
---|---|
tuple[str, list[int, str]]
|
A tuple of the SQL query and parameters. |
Source code in onconova/terminology/fields.py
get_prep_lookup()
¶
Prepares the right-hand side (rhs) of the lookup before executing a query.
This method ensures that the lookup is only applied to fields of type CodedConceptField by checking the alias of the left-hand side (lhs). If the rhs is an instance of a Django model, it converts rhs to the primary key of that model. It then calls the parent class's get_prep_lookup method for any additional preparation.
Raises:
Type | Description |
---|---|
FieldError
|
If the lookup is not applied to a CodedConceptField field. |
Source code in onconova/terminology/fields.py
CodedConceptField(terminology, multiple=False, null=False, blank=False, _to=None, on_delete=models.PROTECT, **kwargs)
¶
CodedConceptField(terminology: type[CodedConceptModel], *, multiple: Literal[False] = False, null: Literal[False] = False, blank=False, _to: type[CodedConceptModel] | None = None, on_delete=models.PROTECT, **kwargs) -> models.ForeignKey[CodedConceptModel]
Factory function for creating a Django relation field (ForeignKey or ManyToManyField) to a terminology model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
type[CodedConceptModel]
|
The target model class for the relationship. |
required |
|
bool
|
If True, returns a ManyToManyField; if False, returns a ForeignKey. Defaults to False. |
False
|
|
bool
|
If True, allows null values. Used only for ManyToManyField. Defaults to False. |
False
|
|
bool
|
If True, allows blank values. Defaults to False. |
False
|
|
type[CodedConceptModel] | None
|
Alternate target model for the relationship. If provided, overrides terminology. Defaults to None. |
None
|
|
Any
|
Deletion behavior for ForeignKey. Defaults to models.PROTECT. |
PROTECT
|
|
dict
|
Additional keyword arguments passed to the underlying field. |
{}
|
Returns:
Type | Description |
---|---|
ForeignKey[CodedConceptModel] | ForeignKey[CodedConceptModel | None] | ManyToManyField
|
A Django ForeignKey field (if multiple=False) or ManyToManyField (if multiple=True) configured to point to the terminology model. |
Raises:
Type | Description |
---|---|
AssertionError
|
If neither terminology nor _to is specified. |