Tharuka Ruwan
Tharuka Ruwan

Reputation: 35

How to view relational data in both snippets in Django Wagtail?

I have defined two models "A" and "B" in Django Wagtail. Model "A" has a ManyToManyField relation with "B". I use Wagtail snippets to edit them in the Admin panel. Is it possible to view both relational data items in each admin snippets? If so, I wanted to restrict the edit feature in model "A".

Upvotes: 0

Views: 224

Answers (1)

Dan Swain
Dan Swain

Reputation: 3098

Rather than using snippets, I would encourage you to use Wagtail's ModelAdmin (reference). With ModelAdmin, you define a wagtail_hooks.py file in your app folder, and in that file you place the definitions of how you want the models to appear in the Wagtail admin (this construct is similar to how you would define things in Django's admin.py). Then, in your models.py file, you will define panels for each model in a similar manner to how you define panels for your Page-based models, and the Wagtail admin will use these panel definitions when displaying a model instance for editing. You can then customize the various views as needed, e.g., you can restrict the edit feature in model "A" as you stated (reference).

Upvotes: 1

Related Questions