Skip to content

Commit

Permalink
fixes default fields creation
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Jul 3, 2024
1 parent 3c4ebdf commit a9f6493
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Test
if: needs.changes.outputs.run_tests
run: |
pdm run pytest tests --junit-xml junit-${{ matrix.python-version }}-${{matrix.django-version}}.xml
pdm run pytest tests --create-db --junit-xml junit-${{ matrix.python-version }}-${{matrix.django-version}}.xml
- name: Upload pytest test results
uses: actions/upload-artifact@v4
Expand Down
25 changes: 15 additions & 10 deletions src/hope_flex_fields/apps.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
from django.apps import AppConfig
from django.db.models.signals import post_migrate

from strategy_field.utils import fqn


def create_default_fields(sender, **kwargs):
from hope_flex_fields.models import FieldDefinition
from hope_flex_fields.registry import field_registry
from hope_flex_fields.utils import get_kwargs_for_field

for fld in field_registry:
FieldDefinition.objects.get_or_create(
name=fld.__name__,
field_type=fqn(fld),
defaults={"attrs": get_kwargs_for_field(fld)},
)


class Config(AppConfig):
name = "hope_flex_fields"
verbose_name = "Flex Fields"

def ready(self):
from hope_flex_fields.models import FieldDefinition
from hope_flex_fields.registry import field_registry
from hope_flex_fields.utils import get_kwargs_for_field

for fld in field_registry:
FieldDefinition.objects.get_or_create(
name=fld.__name__,
field_type=fqn(fld),
defaults={"attrs": get_kwargs_for_field(fld)},
)
post_migrate.connect(create_default_fields, sender=self)

0 comments on commit a9f6493

Please sign in to comment.