Register new column created by SQL

* .. using FakeAddField model type
* .. without doing this, Django won't know
     about the field we created using raw SQL
This commit is contained in:
Jim Ladd 2021-02-08 15:31:25 -08:00
parent d10d1963c1
commit 6ff15a928a
2 changed files with 18 additions and 0 deletions

View File

@ -63,6 +63,16 @@ def migrate_event_data(apps, schema_editor):
cursor.execute(
f'DROP TABLE {tblname}_old'
)
class FakeAddField(migrations.AddField):
def database_forwards(self, *args):
# this is intentionally left blank, because we're
# going to accomplish the migration with some custom raw SQL
pass
class Migration(migrations.Migration):
dependencies = [
@ -71,4 +81,9 @@ class Migration(migrations.Migration):
operations = [
migrations.RunPython(migrate_event_data),
FakeAddField(
model_name='jobevent',
name='job_created',
field=models.DateTimeField(editable=False),
),
]

View File

@ -482,6 +482,9 @@ class JobEvent(BasePlaybookEvent):
default='',
editable=False,
)
job_created = models.DateTimeField(
editable=False
)
def get_absolute_url(self, request=None):
return reverse('api:job_event_detail', kwargs={'pk': self.pk}, request=request)