You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0002_remove_content_type_name.py 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from django.db import migrations, models
  2. def add_legacy_name(apps, schema_editor):
  3. ContentType = apps.get_model('contenttypes', 'ContentType')
  4. for ct in ContentType.objects.all():
  5. try:
  6. ct.name = apps.get_model(ct.app_label, ct.model)._meta.object_name
  7. except LookupError:
  8. ct.name = ct.model
  9. ct.save()
  10. class Migration(migrations.Migration):
  11. dependencies = [
  12. ('contenttypes', '0001_initial'),
  13. ]
  14. operations = [
  15. migrations.AlterModelOptions(
  16. name='contenttype',
  17. options={'verbose_name': 'content type', 'verbose_name_plural': 'content types'},
  18. ),
  19. migrations.AlterField(
  20. model_name='contenttype',
  21. name='name',
  22. field=models.CharField(max_length=100, null=True),
  23. ),
  24. migrations.RunPython(
  25. migrations.RunPython.noop,
  26. add_legacy_name,
  27. hints={'model_name': 'contenttype'},
  28. ),
  29. migrations.RemoveField(
  30. model_name='contenttype',
  31. name='name',
  32. ),
  33. ]