티스토리 뷰
(macOS)[python][django][RaspberryPi] ERP platform - 2
jinozpersona 2021. 4. 19. 11:28Sales / List : models - urls - views - templates
Quotation : urls - views - templates
Raspi-server Test : git
INTRO
* local / server terminal 구분 : [macOS] / [Raspi]
** venv 표기 : (pyERP)
*** Django MTV Model 참고 : [python] django(장고, 웹 프레임워크), MTV Architecture: Model-Template-View
Raspi : server
- Python : 3.7.3
- django : 3.2
macOS : local-dev
- Python : 3.9.4
- django : 3.2
@ macOS : local-dev
1. Sales / List : models - urls - views - templates
Sales Models : DB
{SublimeText} tapp/models.py
# -*- coding: utf-8 -*-
#
from django.conf import settings
from django.db import models
class SalesData(models.Model):
num_cnt = models.IntegerField(primary_key=True)
company = models.CharField('Company', max_length=128, null=False)
site = models.CharField('Site', max_length=128, null=False)
customer = models.CharField('담당자', max_length=128, null=False)
category = models.CharField('제품구분', max_length=128, null=False)
item = models.CharField('품명', max_length=128, null=False)
quantity = models.IntegerField('수량', null=False)
dateShip = models.DateField('납품일', null=True)
drawID = models.CharField('DrawingID', max_length=128, null=True)
frameID = models.CharField('FrameID', max_length=128, null=True)
note = models.CharField('비고', max_length=128, null=True)
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True)
def __str__(self):
return self.item
[macOS](pyERP)testerp$ ./manage.py makemigrations
[macOS](pyERP)testerp$ ./manage.py migrate
urls : tapp/list
{SublimeText} tapp/urls.py
from django.contrib import admin
from django.urls import path
from tapp import views
urlpatterns = [
path('', views.index_app, name='index_app'),
path('list/', views.SalesList, name='tapp_list'),
]
views : List
{SublimeText} tapp/views.py
# -*- coding: utf-8 -*-
from django.shortcuts import render
from tapp.models import SalesData
def index(request):
return render(request, 'index.html')
def index_app(request):
return render(request, 'index_app.html')
def SalesList(request):
SalesDatas = SalesData.objects.all()
context = {'SalesDatas':SalesDatas}
return render(request, 'tapp_list.html', context)
templates : tapp_list
{SublimeText} tapp/templates/tapp_list.html
<!DOCTYPE html>
<html lang="ko">
<head>
<!-- meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<title>SalesList</title>
<td><a href="{% url 'index' %}"><B>Home</B></a></td>
<td><a href="{% url 'index_app' %}"><B>tapp</B></a></td>
<td><B>tapp_list</B></td>
</head>
<body>
<br><br><br>
<div>
<table>
<thead>
<tr>
<td><B>No.</B></td>
<td><B>Company</B></td>
<td><B>Site</B></td>
<td><B>Customer</B></td>
<td><B>제품구분</B></td>
<td><B>품명</B></td>
<td><B>수량</B></td>
<td><B>납품일</B></td>
<td><B>DrawingID</B></td>
<td><B>FrameID</B></td>
<td><B>비고</B></td>
</tr>
</thead>
<tbody>
{% for SalesData in SalesDatas %}
<tr>
<td><a href="quotation/{{ SalesData.pk }}">{{SalesData.num_cnt}}</a></td>
<td>{{SalesData.company}}</td>
<td>{{SalesData.site}}</td>
<td>{{SalesData.customer}}</td>
<td>{{SalesData.category}}</td>
<td>{{SalesData.item}}</td>
<td>{{SalesData.quantity}}</td>
<td>{{SalesData.dateShip}}</td>
<td>{{SalesData.drawID}}</td>
<td>{{SalesData.frameID}}</td>
<td>{{SalesData.note}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
2. Quotation : urls - views - templates
urls : tapp/list/quotation
{SublimeText} tapp/urls.py
from django.contrib import admin
from django.urls import path
from tapp import views
urlpatterns = [
path('', views.index_app, name='index_app'),
path('list/', views.SalesList, name='tapp_list'),
path('list/quotation/<int:pk>/', views.Quotations, name='quotation'),
]
views : Quotations
{SublimeText} tapp/views.py
# -*- coding: utf-8 -*-
from django.shortcuts import render
from tapp.models import SalesData
def index(request):
return render(request, 'index.html')
def index_app(request):
return render(request, 'index_app.html')
def SalesList(request):
SalesDatas = SalesData.objects.all()
context = {'SalesDatas':SalesDatas}
return render(request, 'tapp_list.html', context)
def Quotations(request, pk):
Quotation = SalesData.objects.get(pk=pk)
context = {'Quotation':Quotation}
return render(request, 'quotation.html', context)
templates : quotation/<pk>
{SublimeText} tapp/templates/quotation.html
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Quotation_tapp</title>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
overflow:hidden;padding:8px 10px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
font-weight:normal;overflow:hidden;padding:8px 10px;word-break:normal;}
.tg .tg-j4pq{background-color:#efefef;border-color:#000000;text-align:center;vertical-align:top}
.tg .tg-wp8o{border-color:#000000;text-align:center;vertical-align:top}
.tg .tg-jbyd{background-color:#ffffff;border-color:#000000;text-align:center;vertical-align:top}
.tg .tg-ymap{background-color:#ffffff;border-color:#000000;font-family:Arial, Helvetica, sans-serif !important;;font-size:28px;
text-align:center;vertical-align:middle}
.tg .tg-73oq{border-color:#000000;text-align:left;vertical-align:top}
.tg .tg-fm1z{background-color:#f0f0f0;border-color:#000000;text-align:center;vertical-align:top}
.tg .tg-xwyw{border-color:#000000;text-align:center;vertical-align:middle}
</style>
</head>
<table class="tg" style="undefined;table-layout: fixed; width: 800px">
<colgroup>
<col style="width: 50px">
<col style="width: 240px">
<col style="width: 70px">
<col style="width: 70px">
<col style="width: 70px">
<col style="width: 70px">
<col style="width: 70px">
<col style="width: 70px">
<col style="width: 70px">
<col style="width: 70px">
</colgroup>
<thead>
<tr>
<th class="tg-jbyd" colspan="2" rowspan="2"><img src="{% static 'logo_w_persona.png' %}" alt="Image" width="180" height="42"></th>
<th class="tg-ymap" colspan="8" rowspan="2">견 적 서</th>
</tr>
<tr>
</tr>
</thead>
<tbody>
<tr>
<td class="tg-wp8o" colspan="3">{{Quotation.company}}</td>
<td class="tg-wp8o" colspan="2"></td>
<td class="tg-j4pq">상호</td>
<td class="tg-j4pq" colspan="4">PERSONA</td>
</tr>
<tr>
<td class="tg-wp8o" colspan="3">{{Quotation.customer}}</td>
<td class="tg-wp8o" colspan="2">귀중</td>
<td class="tg-j4pq">주소</td>
<td class="tg-j4pq" colspan="4">https://jinozblog.tistory.com/</td>
</tr>
<tr>
<td class="tg-73oq" colspan="5" rowspan="2">아래와 같이 견적합니다.</td>
<td class="tg-j4pq">업태</td>
<td class="tg-j4pq">제조</td>
<td class="tg-j4pq">종목</td>
<td class="tg-j4pq" colspan="2">Machine Parts</td>
</tr>
<tr>
<td class="tg-fm1z">연락처</td>
<td class="tg-fm1z" colspan="4">+82-10-0000-0000</td>
</tr>
<tr>
<td class="tg-73oq" colspan="10"></td>
</tr>
<tr>
<td class="tg-wp8o">No.</td>
<td class="tg-wp8o" colspan="2">Product</td>
<td class="tg-wp8o">Material</td>
<td class="tg-wp8o">Size</td>
<td class="tg-wp8o">Quantity</td>
<td class="tg-wp8o">Cost</td>
<td class="tg-wp8o">Sum</td>
<td class="tg-wp8o" colspan="2">Note</td>
</tr>
<tr>
<td class="tg-wp8o">1</td>
<td class="tg-wp8o" colspan="2">{{Quotation.item}}</td>
<td class="tg-wp8o">{{Quotation.category}}</td>
<td class="tg-wp8o">{{Quotation.layer}}</td>
<td class="tg-wp8o">{{Quotation.quantity}}</td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o" colspan="2"></td>
</tr>
<tr>
<td class="tg-wp8o">2</td>
<td class="tg-wp8o" colspan="2"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o" colspan="2"></td>
</tr>
<tr>
<td class="tg-wp8o">3</td>
<td class="tg-wp8o" colspan="2"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o" colspan="2"></td>
</tr>
<tr>
<td class="tg-wp8o">4</td>
<td class="tg-wp8o" colspan="2"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o" colspan="2"></td>
</tr>
<tr>
<td class="tg-wp8o">5</td>
<td class="tg-wp8o" colspan="2"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o"></td>
<td class="tg-wp8o" colspan="2"></td>
</tr>
<tr>
<td class="tg-wp8o" colspan="5">합계</td>
<td class="tg-73oq" colspan="5"></td>
</tr>
<tr>
<td class="tg-xwyw" rowspan="2" colspan="1">특이사항</td>
<td class="tg-73oq" colspan="9">VAT별도</td>
</tr>
<tr>
<td class="tg-73oq" colspan="9">대금지급 / 납기 별도 협의</td>
</tr>
</tbody>
</table>
</html>
config/settings.py
{SublimeText} config/settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
[macOS](pyERP)testerp$ ./manage.py collectstatic
[macOS](pyERP)testerp$ tree
.
├── config
│ ├── __init__.py
│ ├── __pycache__
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── db.sqlite3
├── manage.py
├── secret.json
├── static
│ ├── admin
│ └── logo_w_persona.png
└── tapp
├── __init__.py
├── __pycache__
├── admin.py
├── apps.py
├── migrations
│ ├── 0001_initial.py
│ ├── 0002_auto_20210421_1025.py
│ ├── __init__.py
│ └── __pycache__
├── models.py
├── templates
│ ├── index.html
│ ├── index_app.html
│ ├── quotation.html
│ └── tapp_list.html
├── tests.py
├── urls.py
└── views.py
local-Test : admin에서 Sales 3개항목 생성 후 Test
browser localhost:8000/tapp/list
No.의 번호 클릭
localhost:8000/tapp/list/quotation/1
3. Server Test : git transmission
git push @ macOS : local-dev
[macOS]testerp$ git init
[macOS] git:(master)$ git add .
[macOS] git:(master)$ git commit -m "4th : tapp test"
[macOS] git:(master)$ git remote add origin https://github.com/YourRepoName.git
[macOS] git:(master)$ git push -f origin master
git pull/fetch @ Raspi : server
[Raspi]testerp$ git init
[Raspi]testerp$ git remote add origin https://github.com/YourRepoName.git
[Raspi]testerp$ git pull
[Raspi]testerp$ git fetch --all
[Raspi](pyERP)testerp$ git reset --hard origin/master
Server Test @ Raspi : server
[Raspi]pyERP$ source bin/activate
[Raspi](pyERP)$ cd testerp
[Raspi](pyERP)testerp$ nano config/settings.py
#ALLOWED_HOSTS = ['localhost']
ALLOWED_HOSTS = ['[RaspiIP]']
#%참고%# nginx static path 확인 및 재구동
[Raspi](pyERP)testerp$ nano testerp_nginx.conf
# 해당 Django 프로젝트의 static 경로 (변경 필수!)
location /static {
alias /home/[YourRaspiID]/.virtualenvs/pyERP/testerp/static;
}
[Raspi](pyERP)testerp$ sudo /etc/init.d/nginx restart
[sudo] password for jinozraspi:
[ ok ] Restarting nginx (via systemctl): nginx.service.
[Raspi](pyERP)testerp$ uwsgi --ini testerp.ini
server 구동 확인
server-Test : admin에서 Sales 3개항목 생성 후 Test
local Test 결과와 동일
'python > django_ERP1' 카테고리의 다른 글
(macOS)[python][django][RaspberryPi] ERP platform - 4 (0) | 2021.05.03 |
---|---|
(macOS)[python][django][RaspberryPi] ERP platform - 3 (0) | 2021.04.23 |
(macOS)[python][django][RaspberryPi] ERP platform - 1 (0) | 2021.04.15 |
(macOS)[python][django][RaspberryPi] ERP platform - SECRET_KEY 보안설정 (0) | 2021.04.14 |
(macOS)[python][django][RaspberryPi] ERP platform - local/server Test (0) | 2021.04.14 |
- Total
- Today
- Yesterday
- SSH
- server
- CSV
- Python
- DAQ
- vscode
- raspberrypi
- 코로나19
- pyserial
- 확진
- Regression
- analysis
- sublime text
- Pandas
- Model
- MacOS
- 라즈베리파이
- Templates
- Django
- Raspberry Pi
- DS18B20
- ERP
- git
- 자가격리
- github
- r
- COVID-19
- template
- arduino
- 코로나
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |