Skip to content

Commit 615bd9d

Browse files
committed
Add properties for custom fields
1 parent 21584d8 commit 615bd9d

File tree

1 file changed

+17
-0
lines changed
  • django_features/custom_fields/models

1 file changed

+17
-0
lines changed

django_features/custom_fields/models/base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from django_extensions.db.models import TimeStampedModel
1515

1616
from django_features.custom_fields.models.field import CustomField
17+
from django_features.custom_fields.models.field import CustomFieldQuerySet
1718
from django_features.custom_fields.models.value import CustomValue
1819

1920

@@ -184,3 +185,19 @@ def delete(
184185
if delete_custom_values:
185186
self.custom_values.filter(field__choice_field=False).delete()
186187
super().delete(using, keep_parents)
188+
189+
@property
190+
def custom_field_type(self) -> CustomFieldTypeBaseModel | None:
191+
if self._custom_field_type_attr and hasattr(self, self._custom_field_type_attr):
192+
return getattr(self, self._custom_field_type_attr)
193+
return None
194+
195+
@property
196+
def default_custom_fields(self) -> CustomFieldQuerySet:
197+
return CustomField.objects.default_for(self.__class__)
198+
199+
@property
200+
def type_custom_fields(self) -> CustomFieldQuerySet:
201+
if self.custom_field_type:
202+
return self.custom_field_type.custom_fields.all()
203+
return CustomField.objects.none()

0 commit comments

Comments
 (0)