4

I use vanilla django models (they do not inherit from Page) and the modeladmin module of wagtail to replace the standard django admin with the wagtail admin interface. This is all working great, but I now wish to add revision history and rollback to these models.

Wagtail of course has it's own system for managing revisions of objects that inherit from Page, but they would not apply to standard django models. On the other hand, I have been looking at using the django-revisions app to have this functionality. Although this works, django-revisions only provides a standard django admin view, which is not compatible with wagtail, and I would prefer to not have users switching between the two completely different looking admin areas.

Does anybody have experience with managing revisions and rollbacks of standard model instances within the context of wagtail?

MrName
  • 2,363
  • 17
  • 31
  • Is there any reason not to inherit from `Page` and use all that that gives you? I have a situation where I manage Locations and Meetings from within Wagtail inheriting from `Page`, even though they don't appear on my public website at all. It works well. – FlipperPA Jul 08 '19 at 18:54
  • 2
    Wagtail uses ClusterableModel as part of the definition for Page, so maybe you could use that: https://pypi.org/project/django-modelcluster/. I've never done what you're talking about so am not sure how it would work in the Wagtail admin. django-modelcluster includes this statement: "Maybe you have a workflow where your models exist in an incomplete ‘draft’ state for an extended time, or you need to handle multiple revisions, and you don’t want to redesign your database around that requirement." – Dan Swain Jul 08 '19 at 19:44
  • 2
    @FlipperPA I found that the `Page` model had too many strong opinions about it's needs and use case. For example, needing to have a unique slug. When using in a headless mode, this does not make a lot of sense and I found myself jumping through hoops to hack around it. – MrName Jul 08 '19 at 20:03
  • Have you found any good way to do this? I agree that Page is too strong, considering the requirement unique slugs, and built in fields alone, but it might be the easiest way to accomplish it regardless. – dev-jeff Sep 26 '20 at 15:26

1 Answers1

1

You can now have revisions on and customize the admin interface for Snippets. You can either register your model as a Snippet to take advantage of both those features while maintaining the features of ModelAdmin. You can also use RevisionMixin with Wagtail's ModelAdmin.

This RevisionMixin is new in Wagtail 4.0.

Example

Part of an example from the documentation.

from django.db import models

from wagtail.models import RevisionMixin
from wagtail.snippets.models import register_snippet


@register_snippet
class Shirt(RevisionMixin, models.Model):
    name = models.CharField(max_length=255)
    colour = models.ForeignKey("shirts.ShirtColour", on_delete=models.SET_NULL, blank=True, null=True)

    panels = [
        FieldPanel("name"),
        FieldPanel("colour")
    ]
LB Ben Johnston
  • 4,751
  • 13
  • 29
Maranda P.
  • 41
  • 2