1
votes

I have a Wagtail model that extends the base Page model:

models.py

class EmployeePage(Page):
    eid = models.PositiveIntegerField(unique=True)        
    active = models.BooleanField(blank=True)
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    ...

    content_panels = [
        FieldPanel('eid'),            
        FieldPanel('first_name'),
        FieldPanel('last_name'),
    ]

I am only updating the active field directly to the live model via daily API import script, so I want it excluded from the CMS entirely.

import_script.py

employee = EmployeePage.objects.get(eid=imported_row.eid)
employee.active = imported_row.active
employee.save()

I'm able to exclude the active field from the CMS edit view by not including it in the content_panels above, but this appears to just be cosmetic as a value is still always included in page revisions, which is overriding my imported value. How can I have a field that is excluded from page revisions?

1
Any thoughts @gasman?Preston Horn

1 Answers

1
votes

Here's a solution that's kinda hacky, but seems to work. Instead of excluding the field from page revisions, add code to the import script that updates all page revisions.

import_script.py

employee = EmployeePage.objects.get(eid=imported_row.eid)
employee.status = imported_row.status
employee.save()

# Updates all page revisions
revisions = PageRevision.objects.filter(page=employee)
for r in revisions:
    r.active = imported_row.active
    r.save()