Skip to content

Commit 3341b1b

Browse files
committed
Add properties for custom fields
1 parent 2e1393b commit 3341b1b

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

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

0 commit comments

Comments
 (0)