I’m using Forest Admin on a Django project which has a heavily customised admin panel. I’m trying to figure out how to implement these customisations in Forest Admin instead, especially the validation stage between creating a new record in Forest Admin and saving it in the DB.
For example, I want to be perform additional actions once I have clicked “create”.
I would appreciate it if someone could point me in the right direction here. I’ve looked at the Developer Guide, but mostly it’s related to smart fields and so on, which is great, but not what I’m searching for this particular issue.
Thank you very much for your reply, Romain! This is indeed helpful.
I have another question, if I may!
I’m trying to use this example, to protect certain records:
from django.http import HttpResponse
from django_forest.resources.utils.resource.views import DetailView
class CompaniesDetailView(DetailView):
def delete(self, request, pk):
if (pk == 82):
return HttpResponse(
'This record is protected, you cannot remove it.',
status=403);
return super(CompaniesDetailView, self).delete(request, pk)
My questions are:
If I have an app where there are several models, do I need to declare the specific model I’m targeting somewhere in the above code?
Do I have to include this view in the urls.py file which I created inside the app/forest/ directory?
You should create an urls.py file as explained here.
If you need to protect several models, you need to override all the views and add them in the urls.py.
ex:
/companies
/companies/count
/customers/
/customers/count/