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 the your scaffolds like this:

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

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)

    • Tested for different API structures πŸ—οΈ
    • Code coverage at 100% again πŸ‘€
    • Improvements by contributors πŸ‘πŸ» ...
    Source code(tar.gz)
    Source code(zip)
  • 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)

    • 100 % full test coverage πŸš€
    • Major changes and improvements πŸ‘πŸ»
    • Code quality and linting with pylint βœ…
    • CI/CD with travisCI πŸ†
    Source code(tar.gz)
    Source code(zip)
  • 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
A BitField extension for Django Models

django-bitfield Provides a BitField like class (using a BigIntegerField) for your Django models. (If you're upgrading from a version before 1.2 the AP

DISQUS 361 Dec 22, 2022
Use heroicons in your Django and Jinja templates.

heroicons Use heroicons in your Django and Jinja templates. Requirements Python 3.6 to 3.9 supported. Django 2.2 to 3.2 supported. Are your tests slow

Adam Johnson 52 Dec 14, 2022
Custom Django field for using enumerations of named constants

django-enumfield Provides an enumeration Django model field (using IntegerField) with reusable enums and transition validation. Installation Currently

5 Monkeys 195 Dec 20, 2022
Django datatables and widgets, both AJAX and traditional. Display-only ModelForms.

Django datatables and widgets, both AJAX and traditional. Display-only ModelForms. ModelForms / inline formsets with AJAX submit and validation. Works with Django templates.

Dmitriy Sintsov 132 Dec 14, 2022
Dashboad Full Stack utilizando o Django.

Dashboard FullStack completa Projeto finalizado | Informaçáes Cadastro de cliente Menu interatico mostrando quantidade de pessoas bloqueadas, liberada

Lucas Silva 1 Dec 15, 2021
Built from scratch to replicate some of the Django admin functionality and add some more, to serve as an introspective interface for Django and Mongo.

django-mongonaut Info: An introspective interface for Django and MongoDB. Version: 0.2.21 Maintainer: Jazzband (jazzband.co) This Project is Being Mov

Jazzband 238 Dec 26, 2022
Mobile Detect is a lightweight Python package for detecting mobile devices (including tablets).

Django Mobile Detector Mobile Detect is a lightweight Python package for detecting mobile devices (including tablets). It uses the User-Agent string c

Botir 6 Aug 31, 2022
Automatically reload your browser in development.

django-browser-reload Automatically reload your browser in development. Requirements Python 3.6 to 3.10 supported. Django 2.2 to 4.0 supported. Are yo

Adam Johnson 254 Jan 04, 2023
A quick way to add React components to your Django templates.

Django-React-Templatetags This django library allows you to add React (16+) components into your django templates. Features Include react components u

FrΓΆjd Agency 408 Jan 08, 2023
A CTF leaderboard for the submission of flags during a CTF challenge. Built using Django.

🚩 CTF Leaderboard The goal of this project is to provide a simple web page to allow the participants of an CTF to enter their found flags. Also the l

Maurice Bauer 2 Jan 17, 2022
Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Cookiecutter Django Powered by Cookiecutter, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. Documentati

10.1k Jan 08, 2023
Sampling profiler for Python programs

py-spy: Sampling profiler for Python programs py-spy is a sampling profiler for Python programs. It lets you visualize what your Python program is spe

Ben Frederickson 9.5k Jan 01, 2023
Cached file system for online resources in Python

Minato Cache & file system for online resources in Python Features Minato enables you to: Download & cache online recsources minato supports the follo

Yasuhiro Yamaguchi 10 Jan 04, 2023
Create a netflix-like service using Django, React.js, & More.

Create a netflix-like service using Django. Learn advanced Django techniques to achieve amazing results like never before.

Coding For Entrepreneurs 67 Dec 08, 2022
Use Database URLs in your Django Application.

DJ-Database-URL This simple Django utility allows you to utilize the 12factor inspired DATABASE_URL environment variable to configure your Django appl

Jacob Kaplan-Moss 1.3k Dec 30, 2022
Django based webapp pulling in crypto news and price data via api

Deploy Django in Production FTA project implementing containerization of Django Web Framework into Docker to be placed into Azure Container Services a

0 Sep 21, 2022
A django model and form field for normalised phone numbers using python-phonenumbers

django-phonenumber-field A Django library which interfaces with python-phonenumbers to validate, pretty print and convert phone numbers. python-phonen

Stefan Foulis 1.3k Dec 31, 2022
Automated image processing for Django. Currently v4.0

ImageKit is a Django app for processing images. Need a thumbnail? A black-and-white version of a user-uploaded image? ImageKit will make them for you.

Matthew Dapena-Tretter 2.1k Jan 04, 2023
🏭 An easy-to-use implementation of Creation Methods for Django, backed by Faker.

Django-fakery An easy-to-use implementation of Creation Methods (aka Object Factory) for Django, backed by Faker. django_fakery will try to guess the

Flavio Curella 93 Oct 12, 2022
A simple page with paypal payment and confiramtion in django

django-paypal a simple page with paypal payment and confiramtion in django Youtube Video : Paypal Smart Button : https://developer.paypal.com/demo/che

Mahmoud Ahmed 5 Feb 19, 2022