Giter Club home page Giter Club logo

pystock's Introduction

pystock

Django 설치 및 설정

$ pip install Django=4.1.1
$ django-admin startproject pystock

# git pull = git fetch + git merge
$ fatal: refusing to merge unrelated histories
$ git pull origin main --allow-unrelated-histories

$ cd pystock
$ python manage.py runserve
$ python manage.py runserve 8080
$ python manage.py runserve 0:8080

$ django-admin startapp polls
$ django-admin startapp stock

# settings.py
$ ...

$ python manage.py migrate

$ python manage.py makemigrations polls
Migrations for 'polls':
  polls\migrations\0001_initial.py
      - Create model Question
          - Create model Choice
$ python manage.py sqlmigrate polls 0001
$ python manage.py migrate
$ python manage.py migrate polls

# python requirements.txt
$ pip freeze > requirements.txt
$ pip install -r requirements.txt

# input your git access token and save cache
$ git config --global credential.helper cache
$ git push
Username for 'https://github.com': zoonny
Password for 'https://[email protected]': [input your access code]
Everything up-to-date

# remove cache
$ git config --global --unset credential.helper
  • Django Data Handling
$ python manage.py shell
from polls.models import Choice, Question
Question.objects.all()
from django.utils import timezone
q = Question(question_text="What's news?", pub_date=timezone.now())
q.save()
q.id
q.question_text
q.pub_date
q.question_text = 'Hi there?'
q.save()
Question.objects.all()
from polls.models import Choice, Question
Question.objects.all()
Question.objects.filter(id=1)
Question.objects.filter(question_text__startswith='What')
from django.utils import timezone
current_year = timezone.now().year
Question.objects.get(pub_date__year=current_year)
# returned more than one Question -- it returned 3!
# should only one element return
Question.objects.get(id=2)
q = Question.objects.get(pk=1)
q.was_published_recently()
# display child entity (foregin key) - empty set
q.choice_set.all()
# <QuerySet []>
q.choice_set.create(choice_text='Not much', votes=0)
q.choice_set.create(choice_text='The sky', votes=0)
q.choice_set.create(choice_text='HaHa', votes=0)
c = q.choice_set.create(choice_text='hoho', votes=0)
# display super entity
c.question
q.choice_set.all()
q.choice_set.count()
Choice.objects.filter(question__pub_date__year=current_year)
c = q.choice_set.filter(choice_text__startswith='ho')
c.delete()
q.choice_set.all()
  • 수정파일

    • pystock/settings.py
    • pystock/urls.py
  • python formatter

$ pip install black

# setting balck on formatting provider in vscode

Django admin

# 관리자 사용자 생성
$ python3 manage.py createsuperuser
Username: admin
Email address: [email protected]
Password: ******
$ python manage.py runserver

http://localhost:8000/admin

  • manage poll app in admin site
    • code to polls/admin.py
from django.contrib import admin

from .models import Question, Choice

admin.site.register(Question)
admin.site.register(Choice)

Docker

$ docker ps -a
Cannot connect to the Docker daemon at unix:///var/run/docker.sock...
# excute to docker gui
$ docker-compose --version

Etc

$ Get-Content README.md -Wait -Tail 10

pystock's People

Contributors

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