0029_3569_customfield_fields.py 836 B

123456789101112131415161718192021222324252627282930313233343536
  1. from django.db import migrations, models
  2. CUSTOMFIELD_TYPE_CHOICES = (
  3. (100, 'text'),
  4. (200, 'integer'),
  5. (300, 'boolean'),
  6. (400, 'date'),
  7. (500, 'url'),
  8. (600, 'select')
  9. )
  10. def customfield_type_to_slug(apps, schema_editor):
  11. CustomField = apps.get_model('extras', 'CustomField')
  12. for id, slug in CUSTOMFIELD_TYPE_CHOICES:
  13. CustomField.objects.filter(type=str(id)).update(type=slug)
  14. class Migration(migrations.Migration):
  15. atomic = False
  16. dependencies = [
  17. ('extras', '0028_remove_topology_maps'),
  18. ]
  19. operations = [
  20. migrations.AlterField(
  21. model_name='customfield',
  22. name='type',
  23. field=models.CharField(default='text', max_length=50),
  24. ),
  25. migrations.RunPython(
  26. code=customfield_type_to_slug
  27. ),
  28. ]