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
Django server-side adapter for Inertia.js

django-inertia Django server-side new adapter for Inertia.js. Getting Started Install the package pip install django-inertia Configure your project A

Samuel Girardin 14 Sep 16, 2022
A set of high-level abstractions for Django forms

django-formtools Django's "formtools" is a set of high-level abstractions for Django forms. Currently for form previews and multi-step forms. This cod

Jazzband 621 Dec 30, 2022
This is a personal django website for forum posts

Django Web Forum This is a personal django website for forum posts It includes login, registration and forum posts with date time. Tech / Framework us

5 May 12, 2022
Bootstrap 4 integration with Django.

django-bootstrap 4 Bootstrap 4 integration for Django. Goal The goal of this project is to seamlessly blend Django and Bootstrap 4. Requirements Pytho

Zostera B.V. 980 Dec 29, 2022
Faker is a Python package that generates fake data for you.

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in yo

Daniele Faraglia 15.2k Jan 01, 2023
A GitHub Action for checking Django migrations

πŸ” Django migrations checker A GitHub Action for checking Django migrations About This repository contains a Github Action that checks Django migratio

Oda 5 Nov 15, 2022
Store model history and view/revert changes from admin site.

django-simple-history django-simple-history stores Django model state on every create/update/delete. This app supports the following combinations of D

Jazzband 1.8k Jan 06, 2023
Djangoblog - A blogging platform built on Django and Python.

djangoblog πŸ‘¨β€πŸ’» A blogging platform built on Django and Python

Lewis Gentle 1 Jan 10, 2022
Django Audit is a simple Django app that tracks and logs requests to your application.

django-audit Django Audit is a simple Django app that tracks and logs requests to your application. Quick Start Install django-audit pip install dj-au

Oluwafemi Tairu 6 Dec 01, 2022
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
GeoDjango provides geospatial extensions to the Django web dev framework

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. All documentation is in the "docs" directo

Paul Smith 20 Sep 20, 2022
Simple tagging for django

django-taggit This is a Jazzband project. By contributing you agree to abide by the Contributor Code of Conduct and follow the guidelines. django-tagg

Jazzband 3k Jan 02, 2023
A Django backed for PostgreSQL using Psycopg 3

A Django backend for PostgreSQL using Psycopg 2 The backend passes the entire Django test suite, but it needs a few modifications to Django and to i

Daniele Varrazzo 42 Dec 16, 2022
A simple Blog Using Django Framework and Used IBM Cloud Services for Text Analysis and Text to Speech

ElhamBlog Cloud Computing Course first assignment. A simple Blog Using Django Framework and Used IBM Cloud Services for Text Analysis and Text to Spee

Elham Razi 5 Dec 06, 2022
Example project demonstrating using Django’s test runner with Coverage.py

Example project demonstrating using Django’s test runner with Coverage.py Set up with: python -m venv --prompt . venv source venv/bin/activate python

Adam Johnson 5 Nov 29, 2021
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 Dec 17, 2022
Wagtail - Vue - Django : The initial environment of full-stack local dev web app with wagtail and vue

Wagtail - Vue - Django : The initial environment of full-stack local dev web app with wagtail and vue. A demo to show how to use .vue files inside django app.

Quang PHAM 2 Oct 20, 2022
Store model history and view/revert changes from admin site.

django-simple-history django-simple-history stores Django model state on every create/update/delete. This app supports the following combinations of D

Jazzband 1.8k Jan 08, 2023
PEP-484 type hints bindings for the Django web framework

mypy-django Type stubs to use the mypy static type-checker with your Django projects This project includes the PEP-484 compatible "type stubs" for Dja

Machinalis 223 Jun 17, 2022
A simple app that provides django integration for RQ (Redis Queue)

Django-RQ Django integration with RQ, a Redis based Python queuing library. Django-RQ is a simple app that allows you to configure your queues in djan

RQ 1.6k Jan 06, 2023