When I follow the guide for Django to create a smart action, nothing happens after python manage.py runserver
Do we have to create a Django application called app at the root of the project as follows:
app/forest/users.py
from django_forest.utils.collection import Collection
from core.models import User
class UserForest(Collection):
def load(self):
self.actions = [{
'name': 'Refund order'
}]
Collection.register(UserForest, User)
app/urls.py
from django.urls import path
from django.views.decorators.csrf import csrf_exempt
from . import views
app_name = 'app'
urlpatterns = [
path('/actions/refund-user', csrf_exempt(views.RefundUserView.as_view()), name='refund-user'),
]
app/views.py
from django.http import JsonResponse
from django_forest.utils.views.action import ActionView
class RefundUserView(ActionView):
def post(self, request, *args, **kwargs):
# Add your own logic, like calling a Stripe API for instance
return JsonResponse({'success': 'Order refunded!'})
We have a User model in core/ and also added path('forest', include('app.urls')), in api/urls.py
Expected behavior
A smart action to be created and available in the UI.