Giter Club home page Giter Club logo

create-automatic-api's Introduction

create-automatic-api

Generating API automatically with Django

  • Create virtual environment:
virtualenv venv -p C:\Python36\python.exe
.\venv\Scripts\activate
  • Install packages:
pip3 install django djangorestframework drf-generators
  • Auto generate requirements.txt:
pip3 freeze > requirements.txt
  • Create Django project:
django-admin startproject config .
python .\manage.py startapp bills
  • Include new apps in settings.py:
INSTALLED_APPS = [
 ‘django.contrib.admin’,
 ‘django.contrib.auth’,
 ‘django.contrib.contenttypes’,
 ‘django.contrib.sessions’,
 ‘django.contrib.messages’,
 ‘django.contrib.staticfiles’,
 ‘bills’,
 ‘rest_framework’,
 ‘drf_generators’,
]
  • Create sqlite3 database:
python .\manage.py migrate
  • Sqlite3 database schema:
CREATE TABLE bill (
    id             INTEGER        PRIMARY KEY AUTOINCREMENT
                                  NOT NULL,
    name           VARCHAR (255)  NOT NULL,
    date           DATETIME       NOT NULL,
    ident_category INTEGER        NOT NULL
                                  REFERENCES category (id),
    price          DECIMAL (7, 2) DEFAULT (0),
    comment        TEXT
);

CREATE TABLE category (
    id        INTEGER       PRIMARY KEY AUTOINCREMENT
                            NOT NULL,
    name      VARCHAR (255) NOT NULL,
    operation INTEGER       NOT NULL
);
  • Generate django models:
python .\manage.py inspectdb bill category > .\bills\models.py
  • Register class in admin.py:
from django.contrib import admin
from django.apps import apps

app = apps.get_app_config('bills')

for model_name, model in app.models.items():
    admin.site.register(model)
  • Create superuser:
python .\manage.py createsuperuser
  • Create migrations and apply:
python .\manage.py makemigrations
python .\manage.py migrate
  • Fix config/urls.py:
urlpatterns = [
  path(‘admin/’, admin.site.urls),
  path(‘’, include(bills.urls’)),
]
  • Define Pagination in settings.py:
REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 15
}
  • Run server:
python .\manage.py runserver

create-automatic-api's People

Contributors

dependabot[bot] avatar leogregianin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.