Scaffold django rest apis like a champion 🚀

Overview

dr_scaffold blueprint icon

dr_scaffold

Scaffold django rest apis like a champion . said no one before

Tweet

Overview

This library will help you to scaffold full Restful API Resources in seconds using only one command:

$ python manage.py dr_scaffold blog Post body:textfield author:foreignkey:Author
  • models.py with Models and fields generated by the CLI

  • admin.py with Models registered and ready

  • views.py with appropriate ViewSets ready

  • urls.py with appropriate URLs ready.

  • serializers.py with Model Serializers ready

  • and more ...

Installation and usage

For a detailed guide read scaffold django apis like a champion, this library assumes that you have Django Rest Framework. if not, please refer to this guide.

Install dr_scaffold package :

$ pip install dr-scaffold

Add dr_scaffold to your INSTALLED_APPS like this:

INSTALLED_APPS = [
    ...
    'dr_scaffold'
]

Add CORE_FOLDER and API_FOLDER to your settings.py (optional):

CORE_FOLDER = "core_dir/"
API_FOLDER = "api_dir/"

Run your scaffolds like this:

$ python manage.py dr_scaffold blog Post body:textfield author:foreignkey:Author

Supported ViewSet types

We support two types of ViewSets, we support ModelViewSet and we support ViewSets with Mixins.

  • ModelViewSets are the default that get generated with the dr_scaffold command
  • To generate a view with Mixins pass a value of what mixins you want to include like --mixins CRUD this will result in a view with the Create, List, Retrieve, Update, Destroy actions.

Let's generate an API that does only support the Create and Read methods (Read is both list and retrieve):

$ python manage.py dr_scaffold blog Author name:charfield --mixins CR

The command will generate an Author API with a ViewSet like the following:

class AuthorViewSet(
    mixins.CreateModelMixin,
    mixins.ListModelMixin,
    mixins.RetrieveModelMixin,
    viewsets.GenericViewSet
):
    queryset = Author.objects.all()
    serializer_class = AuthorSerializer
    #permission_classes = (permissions.IsAuthenticated,)

    def get_queryset(self):
        #user = self.request.user
        queryset = Author.objects.all()
        #insert specific queryset logic here
        return queryset

    def get_object(self):
        #insert specific get_object logic here
        return super().get_object()

    def create(self, request, *args, **kwargs):
        serializer = AuthorSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response(serializer.data)

    def list(self, request, *args, **kwargs):
        queryset = self.get_queryset()
        serializer = AuthorSerializer(queryset, many=True)
        return Response(serializer.data)

    def retrieve(self, request, *args, **kwargs):
        instance = self.get_object()
        serializer = AuthorSerializer(instance=instance)
        return Response(serializer.data)

Supported field types

We support most of django field types.

Contributors

This project exists thanks to all the people who contribute. [Contribute]

Comments
  • Suggestion: rename create_date field to created

    Suggestion: rename create_date field to created

    I suggest rename create_date to created.

    Because if you want to use (CursorPagination)(https://www.django-rest-framework.org/api-guide/pagination/#cursorpagination) you need of the created field. And particularly I find this a more conventional name.

    opened by rg3915 4
  • Remove : of first and second argument. close #25 (Sourcery refactored)

    Remove : of first and second argument. close #25 (Sourcery refactored)

    Pull Request #45 refactored by Sourcery.

    Since the original Pull Request was opened as a fork in a contributor's repository, we are unable to create a Pull Request branching from it.

    To incorporate these changes, you can either:

    1. Merge this Pull Request instead of the original, or

    2. Ask your contributor to locally incorporate these commits and push them to the original Pull Request

      Incorporate changes via command line
      git fetch https://github.com/Abdenasser/dr_scaffold pull/45/head
      git merge --ff-only FETCH_HEAD
      git push

    NOTE: As code is pushed to the original Pull Request, Sourcery will re-run and update (force-push) this Pull Request with new refactorings as necessary. If Sourcery finds no refactorings at any point, this Pull Request will be closed automatically.

    See our documentation here.

    Run Sourcery locally

    Reduce the feedback loop during development by using the Sourcery editor plugin:

    Help us improve this pull request!

    opened by sourcery-ai[bot] 4
  • Optional parameters (Sourcery refactored)

    Optional parameters (Sourcery refactored)

    Pull Request #60 refactored by Sourcery.

    Since the original Pull Request was opened as a fork in a contributor's repository, we are unable to create a Pull Request branching from it.

    To incorporate these changes, you can either:

    1. Merge this Pull Request instead of the original, or

    2. Ask your contributor to locally incorporate these commits and push them to the original Pull Request

      Incorporate changes via command line
      git fetch https://github.com/Abdenasser/dr_scaffold pull/60/head
      git merge --ff-only FETCH_HEAD
      git push

    NOTE: As code is pushed to the original Pull Request, Sourcery will re-run and update (force-push) this Pull Request with new refactorings as necessary. If Sourcery finds no refactorings at any point, this Pull Request will be closed automatically.

    See our documentation here.

    Run Sourcery locally

    Reduce the feedback loop during development by using the Sourcery editor plugin:

    Help us improve this pull request!

    opened by sourcery-ai[bot] 2
  • Optional parameters

    Optional parameters

    This adds functionality for optional parameters ~and resolves a bug with default table names: https://docs.djangoproject.com/en/1.10/ref/models/options/#db-table~

    Edit: As an alternative to db name we can change confiuration in admin file so that the app wil take in account default table name.

    opened by matej2 2
  • Sourcery refactored main branch

    Sourcery refactored main branch

    Branch main refactored by Sourcery.

    If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

    See our documentation here.

    Run Sourcery locally

    Reduce the feedback loop during development by using the Sourcery editor plugin:

    Review changes via command line

    To manually merge these changes, make sure you're on the main branch, then run:

    git fetch origin sourcery/main
    git merge --ff-only FETCH_HEAD
    git reset HEAD^
    

    Help us improve this pull request!

    opened by sourcery-ai[bot] 2
  • Sourcery refactored dev branch

    Sourcery refactored dev branch

    Branch dev refactored by Sourcery.

    If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

    See our documentation here.

    Run Sourcery locally

    Reduce the feedback loop during development by using the Sourcery editor plugin:

    Review changes via command line

    To manually merge these changes, make sure you're on the dev branch, then run:

    git fetch origin sourcery/dev
    git merge --ff-only FETCH_HEAD
    git reset HEAD^
    

    Help us improve this pull request!

    opened by sourcery-ai[bot] 2
  • Fix second argument on the command line to remove special character

    Fix second argument on the command line to remove special character

    If type python manage.py dr_scaffold blog Article: title:char body:text

    type : before or after model name

    This generate

    class Article:(models.Model):
        title = models.CharField(max_length=255, null=True, blank=True)
        body = models.TextField(null=True, blank=True)
        create_date = models.DateTimeField(auto_now_add=True)
    
        class Meta:
            verbose_name_plural = "Article:s"
    

    Article with two points.

    Suggestion

    Address this in the argument on command line.

    good first issue 
    opened by rg3915 2
  • Add some Files for Environment Configuration

    Add some Files for Environment Configuration

    What's this PR do?

    • Add A little Configuration for the Repository environment for helping other Contributors respect the Text Style, also adding a Depandabot for checking the daily Updates relate to the new Version in some Packages.

    Any background context you want to provide?

    What ticket or issue # does this fix?

    Closes #[issue number]

    Definition of Done (check if considered and/or addressed):

    • [ ] Are all backward-incompatible changes documented in this PR?
    • [ ] Have all new dependencies been documented in this PR?
    • [x] Has the appropriate documentation been updated (if applicable)?
    • [ ] Have you written tests to prove this change works (if applicable)?
    opened by yezz123 2
  • Remove redundant call of file.close on closed files

    Remove redundant call of file.close on closed files

    What's this PR do?

    Remove redundant call of file.close on closed files

    Any background context you want to provide?

    What ticket or issue # does this fix?

    Improves code

    Definition of Done (check if considered and/or addressed):

    • [x] Are all backwards incompatible changes documented in this PR?
    • [x ] Have all new dependencies been documented in this PR?
    • [x ] Has the appropriate documentation been updated (if applicable)?
    • [x ] Have you written tests to prove this change works (if applicable)?
    opened by elmkarami 2
  • Bump django from 3.2.12 to 3.2.13

    Bump django from 3.2.12 to 3.2.13

    Bumps django from 3.2.12 to 3.2.13.

    Commits
    • 08e6073 [3.2.x] Bumped version for 3.2.13 release.
    • 9e19acc [3.2.x] Fixed CVE-2022-28347 -- Protected QuerySet.explain(**options) against...
    • 2044dac [3.2.x] Fixed CVE-2022-28346 -- Protected QuerySet.annotate(), aggregate(), a...
    • bdb92db [3.2.x] Fixed #33628 -- Ignored directories with empty names in autoreloader ...
    • 70035fb [3.2.x] Added stub release notes for 3.2.13 and 2.2.28.
    • 7e7ea71 [3.2.x] Reverted "Fixed forms_tests.tests.test_renderers with Jinja 3.1.0+."
    • 610ecc9 [3.2.x] Fixed forms_tests.tests.test_renderers with Jinja 3.1.0+.
    • 754af45 [3.2.x] Fixed typo in release notes.
    • 6f30916 [3.2.x] Added CVE-2022-22818 and CVE-2022-23833 to security archive.
    • 1e6b555 [3.2.x] Post-release version bump.
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump django from 3.2.6 to 3.2.12

    Bump django from 3.2.6 to 3.2.12

    Bumps django from 3.2.6 to 3.2.12.

    Commits
    • fdf209e [3.2.x] Bumped version for 3.2.12 release.
    • d161335 [3.2.x] Fixed CVE-2022-23833 -- Fixed DoS possiblity in file uploads.
    • 1a1e827 [3.2.x] Fixed CVE-2022-22818 -- Fixed possible XSS via {% debug %} template tag.
    • a7e89fe [3.2.x] Added stub release notes for 3.2.12 and 2.2.27.
    • 027f4c4 [3.2.x] Added CVE-2021-45115, CVE-2021-45116, and CVE-2021-45452 to security ...
    • 0a9a46a [3.2.x] Post-release version bump.
    • 6e499a2 [3.2.x] Bumped version for 3.2.11 release.
    • 8d2f7cf [3.2.x] Fixed CVE-2021-45452 -- Fixed potential path traversal in storage sub...
    • c7fe895 [3.2.x] Fixed CVE-2021-45116 -- Fixed potential information disclosure in dic...
    • a8b32fe [3.2.x] Fixed CVE-2021-45115 -- Prevented DoS vector in UserAttributeSimilari...
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
Releases(v2.1.2)
  • v2.1.2(Feb 13, 2022)

    • minor changes and support for the latest python versions
    • now "created" and "updated" fields will be included in generated models
    • minor bug fixes

    thanks to our new contributors @aymaneMx @leogregianin 🥇

    Source code(tar.gz)
    Source code(zip)
  • v2.1.1(Sep 19, 2021)

    Generates model representation __str__() based on model fields.

    we had the option to chose between generating the representation using only the first field and using all the fields, we've chosen the latter because we sometimes prefer to let the developer delete what he doesn't need from a scaffolded output than letting him add things manually while asking why we didn't do that for him 🎁 .

    class Person(models.Model):
        first_name = models.CharField(max_length=50)
        last_name = models.CharField(max_length=50)
    
        def __str__(self):
            return '%s %s' % (self.first_name, self.last_name)
    
    Source code(tar.gz)
    Source code(zip)
  • v2.1.0(Sep 12, 2021)

    With v2.1.0 you get:

    • added --tests option for generating tests
    • we generate factories for your models based on factory_boy 🤖
    • we generate tests for your factories based on Pytest ✨
    • we put your core tests under tests/core/$app_name and your api tests under tests/apis/$app_name 💅

    next version will include API endpoints tests

    Source code(tar.gz)
    Source code(zip)
  • v2.0.2(Sep 4, 2021)

    With v2.0.2 you get:

    • sorted & elegant imports in your generated files 🤖
    • better line breaks and code formatting
    • nice colored outputs 💅
    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(Sep 4, 2021)

  • v2.0.0(Aug 31, 2021)

    With this version, we added support for ViewSets using Mixins 🥳 🎉

    • Customize your ViewSets on the fly with --mixins CRUD ⚡ .
    • To only add Create, Read and Update pass --mixins CRU, generate your view with any action you like.
    • C is for create R is for list and retrieve U is update and D is destroy as you might guess.
    • One more thing ... we generate your actions along with everything you'd need inside and your get_queryset(), get_object() and more 🚀 🤖 .
    • We still support ModelViewSets as well, if you want them just drop the --mixins option.

    here is a ViewSet example generated with the help of --mixins CR:

    class AuthorViewSet(
        mixins.CreateModelMixin,
        mixins.ListModelMixin,
        mixins.RetrieveModelMixin,
        viewsets.GenericViewSet
    ):
        queryset = Author.objects.all()
        serializer_class = AuthorSerializer
        #permission_classes = (permissions.IsAuthenticated,)
    
        def get_queryset(self):
            #user = self.request.user
            queryset = Author.objects.all()
            #insert specific queryset logic here
            return queryset
    
        def get_object(self):
            #insert specific get_object logic here
            return super().get_object()
    
        def create(self, request, *args, **kwargs):
            serializer = AuthorSerializer(data=request.data)
            serializer.is_valid(raise_exception=True)
            serializer.save()
            return Response(serializer.data)
    
        def list(self, request, *args, **kwargs):
            queryset = self.get_queryset()
            serializer = AuthorSerializer(queryset, many=True)
            return Response(serializer.data)
    
        def retrieve(self, request, *args, **kwargs):
            instance = self.get_object()
            serializer = AuthorSerializer(instance=instance)
            return Response(serializer.data)
    
    Source code(tar.gz)
    Source code(zip)
  • v1.4.2(Aug 29, 2021)

  • v1.3.0(Aug 28, 2021)

    • Added CORE_FOLDER and API_FOLDER settings in order to organize code and separate concerns in our APIs:
    CORE_FOLDER = "my_core_folder_path/" # you can leave them empty
    API_FOLDER = "my_api_folder_path/"   # or set them to be the same
    
    • Core folder is for models.py admin.py and migrations
    • API folder will contain views.py serializers.py and urls.py
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Aug 24, 2021)

  • v1.0.0(Aug 24, 2021)

  • v1.0-beta.1(Aug 23, 2021)

  • v0.6-alpha(Aug 22, 2021)

Owner
Abdenasser Elidrissi
Hi 👋 I'm Abdenasser and I'm a software engineer ... currently on @python @django and ☕
Abdenasser Elidrissi
Document Web APIs made with Django Rest Framework

DRF Docs Document Web APIs made with Django Rest Framework. View Demo Contributors Wanted: Do you like this project? Using it? Let's make it better! S

Manos Konstantinidis 626 Nov 20, 2022
Django-rest-auth provides a set of REST API endpoints for Authentication and Registration

This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON)

Tivix 2.4k Dec 29, 2022
Embrace the APIs of the future. Hug aims to make developing APIs as simple as possible, but no simpler.

Read Latest Documentation - Browse GitHub Code Repository hug aims to make developing Python driven APIs as simple as possible, but no simpler. As a r

Hug API Framework 6.7k Dec 27, 2022
Django Ninja is a web framework for building APIs with Django and Python 3.6+ type hints.

?? Fast, Async-ready, Openapi, type hints based framework for building APIs

Vitaliy Kucheryaviy 3.8k Jan 4, 2023
A small repository of projects built in my course, REST APIs with Flask and Python.

A small repository of projects built in my course, REST APIs with Flask and Python.

Teclado 1k Jan 5, 2023
Sanic-RESTPlus is an extension for Sanic that adds support for quickly building REST APIs.

Sanic RestPlus Sanic-RESTPlus is an extension for Sanic that adds support for quickly building REST APIs. Sanic-RESTPlus encourages best practices wit

Ashley Sommer 106 Oct 14, 2022
Country-specific Django helpers, to use in Django Rest Framework

django-rest-localflavor Country-specific serializers fields, to Django Rest Framework Documentation (soon) The full documentation is at https://django

Gilson Filho 19 Aug 30, 2022
Mlflow-rest-client - Python client for MLflow REST API

Python Client for MLflow Python client for MLflow REST API. Features: Minimal de

MTS 35 Dec 23, 2022
Web APIs for Django. 🎸

Django REST framework Awesome web-browsable Web APIs. Full documentation for the project is available at https://www.django-rest-framework.org/. Fundi

Encode 24.7k Jan 4, 2023
Creating delicious APIs for Django apps since 2010.

django-tastypie Creating delicious APIs for Django apps since 2010. Currently in beta but being used actively in production on several sites. Requirem

null 3.8k Dec 30, 2022
Authentication for Django Rest Framework

Dj-Rest-Auth Drop-in API endpoints for handling authentication securely in Django Rest Framework. Works especially well with SPAs (e.g React, Vue, Ang

Michael 1.1k Dec 28, 2022
Authentication Module for django rest auth

django-rest-knox Authentication Module for django rest auth Knox provides easy to use authentication for Django REST Framework The aim is to allow for

James McMahon 873 Dec 30, 2022
REST implementation of Django authentication system.

djoser REST implementation of Django authentication system. djoser library provides a set of Django Rest Framework views to handle basic actions such

Sunscrapers 2.2k Jan 1, 2023
A JSON Web Token authentication plugin for the Django REST Framework.

Simple JWT Abstract Simple JWT is a JSON Web Token authentication plugin for the Django REST Framework. For full documentation, visit django-rest-fram

Jazzband 3.3k Jan 4, 2023
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.

drf-yasg - Yet another Swagger generator Generate real Swagger/OpenAPI 2.0 specifications from a Django Rest Framework API. Compatible with Django Res

Cristi Vîjdea 3k Jan 6, 2023
Django REST API with React BoilerPlate

This is a setup of Authentication and Registration Integrated with React.js inside the Django Templates for web apps

Faisal Nazik 91 Dec 30, 2022
Introduction to Django Rest Framework

Introduction to Django Rest Framework This is the repository of the video series Introduction to Django Rest Framework published on YouTube. It is a s

Simple is Better Than Complex 20 Jul 14, 2022
JSON:API support for Django REST framework

JSON:API and Django REST framework Overview JSON:API support for Django REST framework Documentation: https://django-rest-framework-json-api.readthedo

null 1k Dec 27, 2022