Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 0 additions & 78 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,6 @@ Bug fixes:
- Fixes AttributeError when overriding the init function of the CustomFieldBaseModelSerializer because of the params. (`TI-2994 <https://4teamwork.atlassian.net/browse/TI-2994>`_)


2025.5.12 (2025-10-27)
----------------------

No changes.


2025.5.11 (2025-10-27)
----------------------

No changes.


2025.5.10 (2025-10-27)
----------------------

Expand All @@ -51,18 +39,6 @@ Bug fixes:
- Array custom fields get annotated correctly.


2025.5.9 (2025-10-24)
---------------------

No changes.


2025.8.0 (2025-10-24)
---------------------

No changes.


2025.5.8 (2025-10-24)
---------------------

Expand All @@ -79,36 +55,6 @@ Bug fixes:
- Handle None values when setting custom values. (`master <https://4teamwork.atlassian.net/browse/master>`_)


2025.5.5 (2025-10-23)
---------------------

No changes.


2025.5.4 (2025-10-23)
---------------------

No changes.


2025.5.3 (2025-10-23)
---------------------

No changes.


2025.5.2 (2025-10-23)
---------------------

No changes.


2025.5.1 (2025-10-23)
---------------------

No changes.


2025.5.0 (2025-10-23)
---------------------

Expand All @@ -117,30 +63,6 @@ Other changes:
- Improve MappingSerializer and add option for more related fields. (`TI-2893 <https://4teamwork.atlassian.net/browse/TI-2893>`_)


2025.4.3 (2025-10-22)
---------------------

No changes.


2025.3.0 (2025-10-22)
---------------------

No changes.


2025.4.2 (2025-10-22)
---------------------

No changes.


2025.4.1 (2025-10-22)
---------------------

No changes.


2025.4.0 (2025-10-22)
---------------------

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ Your querysets should inherit from `django_features.custom_fields.models.CustomF

Your serializers should inherit from `django_features.custom_fields.serializers.CustomFieldBaseModelSerializer`.

#### Base classes

It is possible to create a base class for the CustomField model and extend it with more attributes and functions:

`CUSTOM_FIELD_BASE_MODEL_CLASS = "example_app.models.CustomFieldBaseModelClass"`

It is possible to create a base class for the CustomFieldQuerSet and extend it with more attributes and functions:

`CUSTOM_FIELD_BASE_QUERYSET_CLASS = "example_app.models.CustomFieldBaseQuerySet"`

### System Message

If you want to use `django_features.system_message`, your base configuration class should inherit from `django_features.system_message.settings.SystemMessageConfigurationMixin`.
Expand Down
5 changes: 3 additions & 2 deletions app/management/commands/create_dummy_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.core.management import BaseCommand

from app.models import Person
from django_features.custom_fields import get_custom_field_model
from django_features.custom_fields.models import CustomField
from django_features.custom_fields.models import CustomValue

Expand Down Expand Up @@ -42,7 +43,7 @@ def handle(self, *args: Any, **options: Any) -> None:
print("Add custom fields")
for i in range(self.NUMBER_OF_CUSTOM_FIELDS):
custom_fields.append(
CustomField(
get_custom_field_model()(
content_type=person_c,
field_type=CustomField.TYPE_CHOICES[field_type][0],
identifier=f"custom_field_{i}",
Expand All @@ -64,7 +65,7 @@ def handle(self, *args: Any, **options: Any) -> None:
)

print("Execute bulk create")
CustomField.objects.bulk_create(custom_fields)
get_custom_field_model().objects.bulk_create(custom_fields)
CustomValue.objects.bulk_create(custom_values)
Person.objects.bulk_create(objects)

Expand Down
10 changes: 9 additions & 1 deletion app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
__all__ = ["Address", "ElectionDistrict", "Municipality", "Person", "PersonType"]
__all__ = [
"Address",
"ElectionDistrict",
"ExtendedCustomField",
"Municipality",
"Person",
"PersonType",
]

from .address import Address
from .custom_field import ExtendedCustomField
from .election_distinct import ElectionDistrict
from .municipality import Municipality
from .person import Person
Expand Down
15 changes: 15 additions & 0 deletions app/models/custom_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from app.web.publishable import PublishableModel
from app.web.publishable import PublishableQuerySet
from django_features.custom_fields.models import CustomField
from django_features.custom_fields.models.field import CustomFieldQuerySet


class ExtendedCustomFieldQuerySet(CustomFieldQuerySet, PublishableQuerySet):
pass


class ExtendedCustomField(CustomField, PublishableModel):
objects = ExtendedCustomFieldQuerySet.as_manager()

class Meta(CustomField.Meta):
pass
2 changes: 2 additions & 0 deletions app/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,6 @@ def CONSTANCE_CONFIG_FIELDSETS(self) -> dict:
},
}

CUSTOM_FIELD_MODEL = "app.ExtendedCustomField"

SECRET_KEY = values.SecretValue()
21 changes: 0 additions & 21 deletions app/tests/custom_fields/factories.py

This file was deleted.

33 changes: 33 additions & 0 deletions app/tests/custom_fields/test_custom_field_base_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django.db.models import QuerySet
from django_extensions.db.models import TimeStampedModel

from app.tests import APITestCase
from app.web.publishable import PublishableModel
from app.web.publishable import PublishableQuerySet
from django_features.custom_fields import models
from django_features.custom_fields.factories import CustomFieldFactory
from django_features.custom_fields.models.field import CustomFieldQuerySet


class CustomFieldBaseClassTestCase(APITestCase):
def test_custom_field_base_model_class(self) -> None:
self.assertTrue(issubclass(models.CustomField, TimeStampedModel))
self.assertTrue(issubclass(models.CustomField, PublishableModel))

def test_edit_custom_field_base_model_class_field(self) -> None:
custom_field: models.CustomField = CustomFieldFactory() # type: ignore
self.assertFalse(custom_field.is_public)
custom_field.is_public = True
self.assertTrue(custom_field.is_public)

def test_custom_field_base_queryset_class(self) -> None:
self.assertTrue(issubclass(CustomFieldQuerySet, QuerySet))
self.assertTrue(issubclass(CustomFieldQuerySet, PublishableQuerySet))

def test_publishable_custom_field_base_queryset_class(self) -> None:
CustomFieldFactory(identifier="field_1")
CustomFieldFactory(identifier="field_2", is_public=True)
CustomFieldFactory(identifier="field_3", is_public=True)
self.assertEqual(3, models.CustomField.objects.all().count())
self.assertEqual(2, models.CustomField.objects.publishable().count())
self.assertEqual(1, models.CustomField.objects.filter(is_public=False).count())
4 changes: 2 additions & 2 deletions app/tests/custom_fields/test_custom_field_base_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from app.models import Person
from app.models import PersonType
from app.tests import APITestCase
from app.tests.custom_fields.factories import CustomFieldFactory
from app.tests.custom_fields.factories import CustomValueFactory
from app.tests.factories import PersonFactory
from app.tests.factories import PersonTypeFactory
from django_features.custom_fields.factories import CustomFieldFactory
from django_features.custom_fields.factories import CustomValueFactory
from django_features.custom_fields.models import CustomField


Expand Down
8 changes: 4 additions & 4 deletions app/tests/custom_fields/test_custom_field_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from app.models import Person
from app.models import PersonType
from app.tests import APITestCase
from app.tests.custom_fields.factories import CustomFieldFactory
from app.tests.custom_fields.factories import CustomValueFactory
from app.tests.factories import PersonFactory
from app.tests.factories import PersonTypeFactory
from django_features.custom_fields.factories import CustomFieldFactory
from django_features.custom_fields.factories import CustomValueFactory
from django_features.custom_fields.models import CustomField
from django_features.custom_fields.models import CustomValue

Expand All @@ -28,7 +28,7 @@ def test_custom_field_base_model_custom_field_type_model(self) -> None:
self.assertEqual(PersonType, Person.objects.get_type_model())

def test_custom_field_base_model_set_char_value(self) -> None:
CustomFieldFactory(
CustomFieldFactory( # type: ignore
identifier="char_value",
content_type=self.person_ct,
field_type=CustomField.FIELD_TYPES.CHAR,
Expand All @@ -54,7 +54,7 @@ def test_custom_field_base_model_set_char_value(self) -> None:
self.assertEqual("Char value", CustomValue.objects.first().value)

def test_custom_field_base_model_set_text_value(self) -> None:
CustomFieldFactory(
CustomFieldFactory( # type: ignore
identifier="text_value",
content_type=self.person_ct,
field_type=CustomField.FIELD_TYPES.TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from app.models import Person
from app.serializers.person import PersonSerializer
from app.tests import APITestCase
from app.tests.custom_fields.factories import CustomFieldFactory
from app.tests.custom_fields.factories import CustomValueFactory
from app.tests.factories import PersonFactory
from django_features.custom_fields.factories import CustomFieldFactory
from django_features.custom_fields.factories import CustomValueFactory
from django_features.custom_fields.models import CustomField
from django_features.custom_fields.models import CustomValue

Expand Down
4 changes: 2 additions & 2 deletions app/tests/custom_fields/test_custom_field_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from app.models import Person
from app.tests import APITestCase
from app.tests.custom_fields.factories import CustomFieldFactory
from app.tests.custom_fields.factories import CustomValueFactory
from django_features.custom_fields.factories import CustomFieldFactory
from django_features.custom_fields.factories import CustomValueFactory
from django_features.custom_fields.models import CustomField
from django_features.custom_fields.serializers import CustomFieldSerializer

Expand Down
2 changes: 1 addition & 1 deletion app/tests/custom_fields/test_custom_field_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from app.models import Address
from app.models import Person
from app.tests import APITestCase
from app.tests.custom_fields.factories import CustomFieldFactory
from django_features.custom_fields.factories import CustomFieldFactory


class CustomFieldViewSetTest(APITestCase):
Expand Down
4 changes: 2 additions & 2 deletions app/tests/system_message/test_system_message_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pluck import pluck

from app.tests import APITestCase
from app.tests.system_message.factories import SystemMessageFactory
from app.tests.system_message.factories import SystemMessageTypeFactory
from django_features.system_message.factories import SystemMessageFactory
from django_features.system_message.factories import SystemMessageTypeFactory


class SystemInfoViewSetTest(APITestCase):
Expand Down
4 changes: 2 additions & 2 deletions app/tests/test_mapping_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from app.models import Person
from app.serializers.person import PersonMappingSerializer
from app.tests import APITestCase
from app.tests.custom_fields.factories import CustomFieldFactory
from app.tests.custom_fields.factories import CustomValueFactory
from app.tests.factories import AddressFactory
from app.tests.factories import ElectionDistrictFactory
from app.tests.factories import PersonFactory
from django_features.custom_fields.factories import CustomFieldFactory
from django_features.custom_fields.factories import CustomValueFactory
from django_features.custom_fields.models import CustomField
from django_features.custom_fields.models import CustomValue

Expand Down
6 changes: 3 additions & 3 deletions app/tests/test_model_field_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from app.models import Address
from app.models import Person
from app.tests import APITestCase
from app.tests.custom_fields.factories import CustomFieldFactory
from django_features.custom_fields.factories import CustomFieldFactory
from django_features.custom_fields.models import CustomField
from django_features.settings.fields import ModelFieldMapping

Expand All @@ -13,12 +13,12 @@ class ModelFieldMappingTestCase(APITestCase):
def setUp(self) -> None:
self.person_ct = ContentType.objects.get_for_model(Person)
self.address_ct = ContentType.objects.get_for_model(Address)
CustomFieldFactory(
CustomFieldFactory( # type: ignore
identifier="person_custom_field",
content_type=self.person_ct,
field_type=CustomField.FIELD_TYPES.CHAR,
)
CustomFieldFactory(
CustomFieldFactory( # type: ignore
identifier="address_custom_field",
content_type=self.address_ct,
field_type=CustomField.FIELD_TYPES.CHAR,
Expand Down
Empty file added app/web/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions app/web/publishable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.db import models
from django_extensions.db.models import TimeStampedModel


class PublishableQuerySet(models.QuerySet):
def publishable(self) -> "PublishableQuerySet":
return self.filter(is_public=True)


class PublishableModel(TimeStampedModel):
is_public = models.BooleanField(default=False)

class Meta:
abstract = True
1 change: 1 addition & 0 deletions changes/TI-2890.other
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the possibility to configure the base class of the CustomField model and the CustomFieldQuerySet. [TI-2890](https://4teamwork.atlassian.net/browse/TI-2890>)
Loading
Loading