Package: dr-scaffold
OverviewThis library will help you to scaffold fullRestful API Resourcesin seconds using only one command:$pythonmanage.pydr_scaffoldblogPostbody:textfieldauthor:foreignkey:Author🎉 Your RESTful Post api resource is ready 🎉models.pywith Models and fields generated by the CLI ⚡admin.pywith Models registered and ready ⚡views.pywith appropriate ViewSets ready⚡urls.pywith appropriate URLs ready.⚡serializers.pywith Model Serializers ready ⚡and more …Installation and usageFor a detailed guide readscaffold django apis like a championThis library assumes that you have setup your project withDjango Rest
Framework.
if not, please refer tothis guide1- Install dr_scaffold package :$pipinstalldr-scaffold2- Adddr_scaffoldto your INSTALLED_APPS like this:INSTALLED_APPS=[...'dr_scaffold']3- If you are using a custom API structure, addCORE_FOLDERandAPI_FOLDERto yoursettings.py:#include a forward slash at the end of eachCORE_FOLDER="my_core_folder/"# you can leave them emptyAPI_FOLDER="my_api_folder/"# or set them to be the same4- Run the your scaffolds like this:$pythonmanage.pydr_scaffoldblogPostbody:textfieldauthor:foreignkey:Author--mixinsCRUD🎉 Your RESTful Post api resource is ready 🎉Generate testsWe support generating tests for your models and apis, you can generate tests by adding–teststo your command like follow:$pythonmanage.pydr_scaffoldblogAuthorname:charfield--testsThis will generate factories for your models and their tests (ViewSets tests will be added soon), we depend onpytestandfactory_boyso you should have them installed in order to run your tests.Also bare in mind that you should run your migrations before running the tests.Generate ViewSet MixinsWe support two types of ViewSets, we supportModelViewSetand we supportViewSetswith Mixins.ModelViewSets are the default that get generated with the dr_scaffold commandTo generate a view with Mixins pass a value of what mixins you want to include like--mixinsCRUDthis will result in a view with the Create, List, Retrieve, Update, Destroy actions.Let’s generate an API that does only support theCreateandReadmethods (Read is both list and retrieve):$pythonmanage.pydr_scaffoldblogAuthorname:charfield--mixinsCR🎉 Your RESTful Post api resource is ready 🎉The command will generate an Author API with a ViewSet like the following:classAuthorViewSet(mixins.CreateModelMixin,mixins.ListModelMixin,mixins.RetrieveModelMixin,viewsets.GenericViewSet):queryset=Author.objects.all()serializer_class=AuthorSerializer#permission_classes = (permissions.IsAuthenticated,)defget_queryset(self):#user = self.request.userqueryset=Author.objects.all()#insert specific queryset logic herereturnquerysetdefget_object(self):#insert specific get_object logic herereturnsuper().get_object()defcreate(self,request,*args,**kwargs):serializer=AuthorSerializer(data=request.data)serializer.is_valid(raise_exception=True)serializer.save()returnResponse(serializer.data)deflist(self,request,*args,**kwargs):queryset=self.get_queryset()serializer=AuthorSerializer(queryset,many=True)returnResponse(serializer.data)defretrieve(self,request,*args,**kwargs):instance=self.get_object()serializer=AuthorSerializer(instance=instance)returnResponse(serializer.data)Supported field typesWe support most of django field types.TODOadd an option to include swagger documentation