GithubHelp home page GithubHelp logo

django_messages_server's Introduction

  1. 가상환경을 위한 poetry brew install poetry poetry init poetry add django==2.2.5 petry shell #가상환경 진입

  2. start project django-admin startproject config . #> add gitignore pyhton python3 manage.py runserver python3 manage.py migrate : 초기 db 설정

config/settings.py

LANGUAGE_CODE = 'ko-kr'
TIME_ZONE = "Asia/Seoul"
  1. 관리자생성 python3 manage.py createsuperuser

  2. message app 생성 python3 manage.py startapp messages

  3. message model 생성 models.py

class Cozmessage(models.Model):

    username = models.CharField(max_length=140)
    text = models.CharField(max_length=140)
    roomname = models.CharField(max_length=140)
    date = models.DateTimeField
    
    def __str__(self):
        return self.name
  1. cozmessages app 등록 config settings.py 셋팅

CUSTOM_APPS = [ "cozmessages.apps.CozmessagesConfig" ]

INSTALLED_APPS = CUSTOM_APPS + SYSTEM_APPS

  1. admin등록 cozmessages/admin.py from .models import Cozmessage
from django.contrib import admin
from .models import Cozmessage

@admin.register(Cozmessage)
class CozmessageAdmin(admin.ModelAdmin):

    list_display = [
        "username",
        "text",
        "roomname"
    ]

    list_filter = [
        "username"
    ]

    search_fields = ["username"]

python3 manage.py makemigrations python3 manage.py migrate

  1. rest framework 설치 poetry add djangorestframework==3.13.0

INSTALLED_APPS = CUSTOM_APPS + THIRD_PARTY_APPS + SYSTEM_APPS

THIRD_PARTY_APPS=[ 'rest_framework', ]

  1. url, view 만들기 cozmessages/urls.py
from django.urls import path
from . import views
urlpatterns = [
    path("", views.cozmessages),
]

config/settings.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('cozmessages/', include("cozmessages.urls")),
]

cozmessages/views.py

from django.http import JsonResponse
from .models import Cozmessage

def cozmessages(request):
    
    all_messages = Cozmessage.objects.all()

cozmessages/serializers.py

django_messages_server's People

Contributors

glen15 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.