Skip to content

Commit 67246da

Browse files
committed
Add for type method to querysets
1 parent a6abf2e commit 67246da

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

django_features/custom_fields/models/field.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def for_model(self, model: models.Model) -> "CustomFieldQuerySet":
1414
content_type__model=model._meta.model_name,
1515
)
1616

17+
def for_type(self, model: models.Model) -> "CustomFieldQuerySet":
18+
return self.select_related("content_type").filter(
19+
type_content_type__app_label=model._meta.app_label,
20+
type_content_type__model=model._meta.model_name,
21+
)
22+
1723

1824
class FieldType:
1925
CHAR = "CHAR"

django_features/custom_fields/models/value.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ def for_model(self, model: models.Model) -> "CustomValueQuerySet":
1212
field__content_type__model=model._meta.model_name,
1313
)
1414

15+
def for_type(self, model: models.Model) -> "CustomValueQuerySet":
16+
return self.select_related("content_type").filter(
17+
field__type_content_type__app_label=model._meta.app_label,
18+
field__type_content_type__model=model._meta.model_name,
19+
)
20+
1521

1622
class CustomValue(TimeStampedModel):
1723
field = models.ForeignKey(

0 commit comments

Comments
 (0)