Package: dj-rest-admin
This is a fork ofBdVade/DRF-adminprojectThis repo has been renamed in order to avoid confusions with BdVade/DRF-admin and will be
mantained by myself.Any contribution and feature requests are welcome!dj-rest-adminA package to generate CRUD endpoints for registered models with the Django-REST Framework.RequirementsDjangoDjango Rest FrameworkInstallationTo install run:pip install drf-adminUsageAdd rest_admin.py in your app dirs for defining RestModelAdminImport dj_rest_admin in the rest_admin.pyCalldj_rest_admin.site.register(Model)Model being the model to registerAdd rest admin to your urls.py file.[Optional] Adddj_rest_adminto yourINSTALLED_APPSfor admin autodiscover.Prerequisiterest_framework should be properly set up to use this package hitch freeA sample of it's configuration in the settings file:REST_FRAMEWORK={'DEFAULT_SCHEMA_CLASS':'rest_framework.schemas.coreapi.AutoSchema','TEST_REQUEST_RENDERER_CLASSES':['rest_framework.renderers.MultiPartRenderer','rest_framework.renderers.JSONRenderer','rest_framework.renderers.TemplateHTMLRenderer',],"DEFAULT_AUTHENTICATION_CLASSES":['rest_framework.authentication.SessionAuthentication','rest_framework.authentication.BasicAuthentication'],"DEFAULT_PERMISSION_CLASSES":['rest_framework.permissions.AllowAny',]}For example:models.pyfromdjango.dbimportmodelsclassTestModel(models.Model):age=models.IntegerField()admin.pyfrom.modelsimportTestModelimportdj_rest_admindj_rest_admin.site.register(TestModel)urls.pyfromrestadminimportsitefromdjango.urlsimportpathurlpatterns=[...path('restadmin/',site.urls),...]CustomizationThis package allows you to specify the following when registering your modelserializer_or_modeladmin: A Model Serializer Class or a subclass ofRestModelAdminpermission_classes: A list of Permission classespagination_classs: A Pagination ClassAn example of how a call to the register method with all 3 would look is :dj_rest_admin.site.register(TestModel,serializer_or_modeladmin=AdminSerializer,permission_classes=[ReadOnly],pagination_class=LargeResultsSetPagination)RestModelAdminexpose the same interface asModelViewSetso you can add the whole customizations thatModelViewSetoffers. This includes:Custom querysetsredifining defaults methodsadd actions as ModelViewSet's exta actionsYou can also register models with theregisterdecoratorExample:fromdj_rest_adminimportregister,RestModelAdminfrom.modelsimportTestModel@register(TestModel)classTestRestModelAdmin(RestModelAdmin):serializer_class=MyCustomSerializer# Optional. A default is provided if None defineddefget_queryset(self):queryset=TestModel.objects.filter(age__lt=30)returnquerysetEndpoint DocumentationThis requires you to have coreapi installedA page to document the Endpoints generated can be accessed by adding the following to your base urls filefromdj_rest_adminimportsiteurlpatterns=[...path('restadmin-docs/',site.docs)...]Using this would require you to have your default schema Class set in your REST_FRAMEWORK config in your settings.py file
E.gREST_FRAMEWORK = { 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' }Run your server and you can find the documentation athttp://127.0.0.1:8000/restadmin-docsNOTE: The Documentation page is restricted to staff only(is_staff has to be True)TestsTo run the tests:From the base directory run :python load_tests.py