Skip to content

Commit

Permalink
Do not create migrations when changing field types
Browse files Browse the repository at this point in the history
Fixes #30, 32.
  • Loading branch information
matthiask committed Oct 2, 2020
1 parent 529610b commit e53b83c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
20 changes: 1 addition & 19 deletions form_designer/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,6 @@
from django.db import models, migrations


field_types = [
("text", "text"),
("email", "email address"),
("longtext", "long text"),
("checkbox", "checkbox"),
("select", "select"),
("radio", "radio"),
("multiple-select", "multiple select"),
("hidden", "hidden"),
]
try:
from form_designer.models import FIELD_TYPES

field_types = [type[:2] for type in FIELD_TYPES]
except Exception:
pass


class Migration(migrations.Migration):

dependencies = []
Expand Down Expand Up @@ -61,7 +43,7 @@ class Migration(migrations.Migration):
(
"type",
models.CharField(
verbose_name="field type", choices=field_types, max_length=20
verbose_name="field type", choices=[("", "")], max_length=20
),
),
(
Expand Down
11 changes: 10 additions & 1 deletion form_designer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ def process(self, form, request):
}


class _StaticChoicesCharField(models.CharField):
"""Does not detect changes to "choices", ever"""

def deconstruct(self):
name, path, args, kwargs = super(_StaticChoicesCharField, self).deconstruct()
kwargs["choices"] = [("", "")]
return name, "django.db.models.CharField", args, kwargs


class FormField(models.Model):
form = models.ForeignKey(
Form, related_name="fields", verbose_name=_("form"), on_delete=models.CASCADE
Expand All @@ -182,7 +191,7 @@ class FormField(models.Model):

title = models.CharField(_("field title"), max_length=100)
name = models.CharField(_("field name"), max_length=100)
type = models.CharField(
type = _StaticChoicesCharField(
_("field type"),
max_length=20,
choices=[(type["type"], type["verbose_name"]) for type in FIELD_TYPES],
Expand Down

0 comments on commit e53b83c

Please sign in to comment.