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)

  • 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
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

О чем этот проект Этот репозиторий с шаблонами для быстрого создания Django проекта. В шаблоне проекта настроены следующий технологий: Django gunicorn

Denis Kustov 16 Oct 20, 2022
English dictionary using Django based on freecodecamp

English Dictionary Hi there, i made this english dictionary using Django based on freecodecamp.org tutorial :) Table of Contents Preview Technologies

Aline Alencar 3 May 09, 2022
Django + NextJS + Tailwind Boilerplate

django + NextJS + Tailwind Boilerplate About A Django project boilerplate/templa

Shayan Debroy 3 Mar 11, 2022
Reusable, generic mixins for Django

django-braces Mixins for Django's class-based views. Documentation Read The Docs Installation Install from PyPI with pip: pip install django-braces Bu

Brack3t 1.9k Jan 05, 2023
This is a template tag project for django to calculate in templates , enjoy it

Calculator-Template-Django this is a template tag project for django to calculate in templates , enjoy it Get Started : 1 - Download Source Code 2 - M

1 Feb 01, 2022
Django-Docker - Django Installation Guide on Docker

Guía de instalación del Framework Django en Docker Introducción: Con esta guía p

Victor manuel torres 3 Dec 02, 2022
User Authentication In Django/Ajax/Jquery

User Authentication In Django/Ajax/Jquery Demo: Authentication System Using Django/Ajax/Jquery Demo: Authentication System Using Django Overview The D

Suman Raj Khanal 10 Mar 26, 2022
Improved Django model inheritance with automatic downcasting

Polymorphic Models for Django Django-polymorphic simplifies using inherited models in Django projects. When a query is made at the base model, the inh

1.4k Jan 03, 2023
Returns unicode slugs

Python Slugify A Python slugify application that handles unicode. Overview Best attempt to create slugs from unicode strings while keeping it DRY. Not

Val Neekman (AvidCoder) 1.3k Dec 23, 2022
A CBV to handle multiple forms in one view

django-shapeshifter A common problem in Django is how to have a view, especially a class-based view that can display and process multiple forms at onc

Kenneth Love 167 Nov 26, 2022
Thumbnails for Django

Thumbnails for Django. Features at a glance Support for Django 2.2, 3.0 and 3.1 following the Django supported versions policy Python 3 support Storag

Jazzband 1.6k Jan 03, 2023
Sistema administrador de contranas desarrollador en Django

Sistema Contrasenas Desarrolado en Django Proyecto sistema de administracion de contraseñas, de la experiencia educativa Programacion Segura Descripci

Ibrain Rodriguez Espinoza 1 Sep 24, 2022
MAC address Model Field & Form Field for Django apps

django-macaddress MAC Address model and form fields for Django We use netaddr to parse and validate the MAC address. The tests aren't complete yet. Pa

49 Sep 04, 2022
A multiprocessing distributed task queue for Django

A multiprocessing distributed task queue for Django Features Multiprocessing worker pool Asynchronous tasks Scheduled, cron and repeated tasks Signed

Ilan Steemers 1.7k Jan 03, 2023
Silk is a live profiling and inspection tool for the Django framework.

Silk is a live profiling and inspection tool for the Django framework. Silk intercepts and stores HTTP requests and database queries before presenting them in a user interface for further inspection:

Jazzband 3.7k Jan 02, 2023
Login System Django

Login-System-Django Login System Using Django Tech Used Django Python Html Run Locally Clone project git clone https://link-to-project Get project for

Nandini Chhajed 6 Dec 12, 2021
Zendesk Assignment - Django Based Ticket Viewer

Zendesk-Coding-Challenge Django Based Ticket Viewer The assignment has been made using Django. Important methods have been scripted in views.py. Excep

Akash Sampurnanand Pandey 0 Dec 23, 2021
PicoStyle - Advance market place website written in django

Advance market place website written in django :) Online fashion store for whole

AminAli Mazarian 26 Sep 10, 2022
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