-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
16 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |