GithubHelp home page GithubHelp logo

testdjangorest's Introduction

TestDjangoRest

Tutorial

https://www.youtube.com/playlist?list=PLo7TNe_pEoMXcsc1dOaFyVGcZK8o-6CCW

Hoc ve Models

code example

    Hoc ve Models
    - cac loai Field co trong django rest
    - def __str__(self): | => format hien thi object tren admin page
    - class Meta: | => them chuc nang sap xep object theo Field, chinh name hien thi cua Model
    - def save(self, *args, **kwargs): | => action while save data in db

code example

    - ForeignKey chu y: co cac kieu on_delete khac nhau

code example

    - OneToOneField chu y: co cac kieu on_delete khac nhau, quan he 1-1

Hoc ve Views

code example tao mot api request don gian

code example

    dung APIView: khong co serializer: postMethod phai tao chay nhu tren

code example

    dung APIView: co su dung serializer: postMethod ngan gon

Hoc Serializers

code example

    dung serializer.Serializer :
    - phai viet ham create, update de khi post va put .save() map voi funtion tren

code example

    su dung ModalSerializer: duoc ho tro het

quay lai voi Views

code example

    generics: ho tro api GET POST PUT DELETE
    Chu y: generics.UpdateAPIView tham so default la 'pk'.
    Muon thay doi phai set: lookup_field ="name_field"

code example

    dung viewSets.ModelViewSet: ho tro tu a -> z

Hoc ve Urls

Co hai kieu dung code example

code example

Setting postgresql

code example

    pip install psycopg2-binary

Docker-compose setup

version: "3"

services:
    postgres:
        container_name: postgres_container
        image: postgres
        environment:
            POSTGRES_USER: admin
            POSTGRES_PASSWORD: admin123
            PGDATA: /data/postgres
        volumes:
            - postgres:/data/postgres
        ports:
            - "5000:5432"
        networks:
            - postgres
        restart: unless-stopped
networks:
    postgres:
        driver: bridge
volumes:
    postgres:

Tool su dung

Using django-seed sinh data ngau nhien

pip install django-seed
khai bao "django_seed" trong setting

python manage.py seed new_app --number=10

debug_toolbar

pip install django-debug-toolbar
khai bao "debug_toolbar" trong setting

Custom Users

code example

delete old db => can migates new app

Authenticated

    khai bao authentication_classes default trong settings:
        REST_FRAMEWORK = {
            "DEFAULT_AUTHENTICATION_CLASSES": ("gateway.authentication.Authentication",)
        }
    "gateway.authentication.Authentication" la class trong app gateway, file authentication

testdjangorest's People

Contributors

quyenld9699 avatar

Watchers

 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.