0

I need to set items in an InlinePanel on a page as 'archived' so they don't display in the InlinePanel. There should only be a few items visible at once but deleting them is not an option as they are required for historical information and reporting etc.

Is there a way to do this without just hiding them with Javascript (which will slow down page loads over time)? If they are archived and removed from the QuerySet via filtering, they are then deleted when the page is published because they are not longer needed by the InlinePanel. I have tried SET_NULL but they are still deleted. Using PROTECT stops the page from being published but this wont work because it's just blocking the inline object from being deleted.

So how could this be done, or is this just asking too much from an InlinePanel?

Basic code example. SET_NULL is ignored and related object is deleted when the page is published.

class Variant(models.Model):

    product = ParentalKey(
        'wagtailcore.Page',
        related_name='variants',
        on_delete=models.SET_NULL,
        null=True,
    )

class Product(Page):

    panels = [
    MultiFieldPanel([
        InlinePanel('variants', label='Item Variants'),
    ]),
    ]
Sammy J
  • 1
  • 2
  • I believe this has been answered here: https://stackoverflow.com/questions/40554215/wagtail-filter-results-of-an-inlinepanel-foreignkey – Sævar Mar 23 '23 at 18:26
  • Does this answer your question? [Wagtail: Filter results of an InlinePanel ForeignKey](https://stackoverflow.com/questions/40554215/wagtail-filter-results-of-an-inlinepanel-foreignkey) – Sævar Mar 23 '23 at 18:28

1 Answers1

0

While I would prefer to be able to do this in a usual Django way. I solved this by editing the file wagtailadmin/edit_handlers/inline_panel.html and checking a archived boolean on the model before rending the child_inline_panel.

This workaround solves the immediate issue but doesn't feel right - there should be a way that is not done through templates.

Sammy J
  • 1
  • 2