djangodjango-rest-frameworkwagtailheadlessmodeladmin

How to share data sets between Wagtail ( ModelAdmin ) and Django Rest API


I´m making a translator app for phrases using Wagtail and Vue. For this purpose I registered the phrases model to Waigtail admin ( using ModelAdmin ) so Editors can add new data sets in the admin tool. Now I have to create the API so the Frontend can get the phrases. But here comes the problem. I can´t find a way to create the API for the phrases. In my understanding theres obviously a necessity for a APIViewSet for ModelAdmin but regarding to the docs theres only PagesAPIViewSet, ImagesAPIViewSet and DocumentsAPIViewSet. I´m a bit confused because it is not a exotic case.

I´m thinking about making a new django app for the phrases API with its own database but I can´t imagine it´s meant to be done like that.


Solution

  • Update

    I solved it now. It works well. Instructions are:

    1. Create ONLY ONE database with two users ( I used postgres ). One for wagtail and one for django rest api.
    2. Grant them all privileges. Info
    3. Setup django rest api ( with its own venv ) with additional app ( for example phrasesapi: python manage.py startapp phrasesapi ). -> connect app to db with django-user.
    4. Setup wagtail ( with its own venv ) with ModelAdmin ( wagtail_hooks ) and an additional app ( for example phrasesapi ). These two apps have to have the exact same names. -> connect app to db with wagtail-user

    Now you can do CRUD for database entries ( in my case phrases ) either with the rest api or with wagtail cms. Leave comment if anything is not clear.