티스토리 뷰

Template 확장

입력 form 만들기

새글 쓰기/수정/삭제

 

Server Test : git transmission : 생략

 

INTRO

* local / server terminal 구분 : [macOS] / [Raspi]

** venv 표기 : (pyERP)

 

Raspi : server

- Python : 3.7.3

- django : 3.2

 

macOS : local-dev

- Python : 3.9.4

- django : 3.2

 

-------------------- platform review -------------------- 

구성 : head / navbar_main / body_top / navbar_sub / body_bottom / footer

프레임(상단) : index_production

프레임(하단) : index_production_detail

 

생산관리 클릭 : index_production 이동

새글쓰기 클릭 : production_new 이동

 

생산품명 클릭 : index_production_detail 이동

수정 클릭 : production_edit 이동

삭제 클릭 : production_delete 이동, 미리보기 생략

 

-------------------- platform review -------------------- 

 

1. home: notice

2. sales

3. production

 다음과 같이 models/forms/urls/views/templates로 구성

 --> models, forms, (admin), urls, views, templates(production)

 

@ macOS 

production

- models

{SublimeText}production/models.py

from django.conf import settings
from django.db import models
from sales.models import Sales


class Production(models.Model):
	sales_id   = models.ForeignKey(Sales, on_delete=models.CASCADE, db_column='sales_id')
	author     = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=False)
	uniq_id    = models.CharField('관리번호', max_length=128, null=False)
	pd_id      = models.AutoField(primary_key=True)
	pd_item    = models.CharField('생산품명', max_length=128, null=False)
	pd_input   = models.IntegerField('생산수량', null=True)
	created_at = models.DateTimeField('생산지시일',auto_now_add=True)
	updated_at = models.DateTimeField('생산수정일',auto_now=True)

	def __str__(self):
		return self.pd_item

- forms

{SublimeText}production/forms.py

from django import forms
from production.models import Production


class ProductionForm(forms.ModelForm):
    class Meta:
        model = Production
        fields = ['sales_id', 'uniq_id', 'pd_item', 'pd_input', 'author']
        widgets = {
            'uniq_id'   : forms.TextInput(attrs={'style':'width: 5em'}),
            'pd_item'   : forms.TextInput(attrs={'style':'width: 8em'}),
            'pd_input'  : forms.TextInput(attrs={'style':'width: 4em'}),
        }

- admin

{SublimeText}production/admin.py

from django.contrib import admin
from production.models import Production


class ProductionAdmin(admin.ModelAdmin):
    search_fields = ['pd_item']

admin.site.register(Production, ProductionAdmin)

- urls

{SublimeText}production/urls.py

from django.contrib import admin
from django.urls import path
from production import views


urlpatterns = [
	path('', views.index_production, name='index_production'),
	path('<int:pk>/', views.index_production_detail, name='index_production_detail'),
	path('new/', views.production_new, name='production_new'),
	path('<int:pk>/edit/', views.production_edit, name='production_edit'),
	path('<int:pk>/delete/', views.production_delete, name='production_delete'),
]

- views

{SublimeText}production/views.py

from django.shortcuts import render, redirect
from production.models import Production
from sales.models import Sales
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from production.forms import ProductionForm


@login_required
def index_production(request):
	productions = Production.objects.all().order_by('-sales_id')
	context = {'productions': productions}
	return render(request, 'index_production.html', context)

@login_required
def index_production_detail(request, pk):
	productions = Production.objects.all().order_by('-sales_id')
	production_view  = Production.objects.get(pk=pk)
	sales_view = Sales.objects.get(pk=production_view.sales_id)
	context = {'productions': productions, 'production_view': production_view, 'sales_view': sales_view}
	return render(request, 'index_production_detail.html', context)

@login_required
def production_new(request):
	productions = Production.objects.all().order_by('-sales_id')
	if request.method == 'POST':
		form = ProductionForm(request.POST)
		if form.is_valid():
			production = Production()
			production.sales_id  = form.cleaned_data['sales_id']
			production.uniq_id   = form.cleaned_data['uniq_id']
			production.pd_item   = form.cleaned_data['pd_item']
			production.pd_input  = form.cleaned_data['pd_input']
			production.author    = form.cleaned_data['author']
			production.save()
			return redirect('/production/')
	else:
		form = ProductionForm()
		pass
	return render(request, 'production_new.html', {'form':form, 'productions':productions})

@login_required
def production_delete(request, pk):
	production_del  = Production.objects.get(pk=pk)
	if production_del.author == User.objects.get(username = request.user.get_username()):
		production_del.delete()
		return redirect('/production/')
	else:
		return render(request, 'warning.html')

@login_required
def production_edit(request, pk):
	productions = Production.objects.all().order_by('-sales_id')
	production  = Production.objects.get(pk=pk)
	if request.method == 'POST':
		form = ProductionForm(request.POST)
		if form.is_valid():
			production.sales_id  = form.cleaned_data['sales_id']
			production.uniq_id   = form.cleaned_data['uniq_id']
			production.pd_item   = form.cleaned_data['pd_item']
			production.pd_input  = form.cleaned_data['pd_input']
			production.author    = form.cleaned_data['author']
			production.save()
			return redirect('/production/')
	else:
		form = ProductionForm()
		pass		
	return render(request, 'production_edit.html', {'form':form, 'productions':productions})

- templates

{SublimeText}production/templates/index_production.html

{% extends 'base.html' %}
<!--navbar_top  -->
{% block navbar_top %}
{% include "navbar_main.html" %}
{% include "navbar_production.html" %}
{% endblock %}

<!-- Main block -->
{% block content1 %}
<h2>생산관리 리스트</h2>
<table>
  <thead>
    <tr>
      <td><B>생산번호</B></td>
      <td><B>수주번호(수주아이템)</B></td>
      <td><B>관리번호</B></td>
      <td><B>생산품명</B></td>
      <td><B>생산수량</B></td>
      <td><B>생산지시자</B></td>
      <td><B>생산지시일</B></td>
      <td><B>생산지시서출력</B></td>
    </tr>
  </thead>

  <tbody>
    {% for production in productions %}
    <tr>
      <td>{{ production.pd_id }}</td>
      <td>{{ production.sales_id }}</td>
      <td>{{ production.uniq_id }}</td>
      <td><a href="{% url 'index_production_detail' production.pk %}">{{ production.pd_item }}</a></td>
      <td>{{ production.pd_input }}</td>
      <td>{{ production.author }}</td>
      <td>{{ production.created_at }}</td>
      <td><a href="#" target='_blank'>Go!</a></td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endblock %}
<!-- End Main block -->

<!--navbar_sub  -->
{% block navbar_sub %}
{% include "navbar_new.html" %}
{% endblock %}
<!-- Sub block -->
{% block content2 %}
{% endblock %}
<!-- End Sub block -->


{SublimeText}production/templates/index_production_detail.html

{% extends 'base.html' %}
<!--navbar_top  -->
{% block navbar_top %}
{% include "navbar_main.html" %}
{% include "navbar_production.html" %}
{% endblock %}

<!-- Main block -->
{% block content1 %}
<h2>생산관리 리스트</h2>
<table>
  <thead>
    <tr>
      <td><B>생산번호</B></td>
      <td><B>수주번호(수주아이템)</B></td>
      <td><B>관리번호</B></td>
      <td><B>생산품명</B></td>
      <td><B>생산수량</B></td>
      <td><B>생산지시자</B></td>
      <td><B>생산지시일</B></td>
      <td><B>생산지시서출력</B></td>
    </tr>
  </thead>

  <tbody>
    {% for production in productions %}
    <tr>
      <td>{{ production.pd_id }}</td>
      <td>{{ production.sales_id }}</td>
      <td>{{ production.uniq_id }}</td>
      <td><a href="{% url 'index_production_detail' production.pk %}">{{ production.pd_item }}</a></td>
      <td>{{ production.pd_input }}</td>
      <td>{{ production.author }}</td>
      <td>{{ production.created_at }}</td>
      <td><a href="#" target='_blank'>Go!</a></td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endblock %}
<!-- End Main block -->

<!--navbar_sub  -->
{% block navbar_sub %}
{% include "navbar_sub.html" %}
{% endblock %}

<!-- Sub block -->
{% block content2 %}
<h3>영업정보</h3>
<table>
  <thead>
    <tr>
      <td><B>수주번호</B></td>
      <td><B>영업담당자</B></td>
      <td><B>고객사</B></td>
      <td><B>Fab-Site</B></td>
      <td><B>고객명</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>AssemblyID</B></td>
      <td><B>비고</B></td>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>{{ sales_view.sales_id }}</td>
      <td>{{ sales_view.author }}</td>
      <td>{{ sales_view.company }}</td>
      <td>{{ sales_view.site }}</td>
      <td>{{ sales_view.customer }}</td>
      <td>{{ sales_view.category }}</td>
      <td>{{ sales_view.item }}</td>
      <td>{{ sales_view.quantity }}</td>
      <td>{{ sales_view.dateShip }}</td>
      <td>{{ sales_view.drawID }}</td>
      <td>{{ sales_view.frameID }}</td>
      <td>{{ sales_view.note }}</td>
    </tr>
  </tbody>
</table>

{% endblock %}

{SublimeText}production/templates/production_edit.html

{% extends 'base.html' %}
<!--navbar_top  -->
{% block navbar_top %}
{% include "navbar_main.html" %}
{% include "navbar_production.html" %}
{% endblock %}

<!-- Main block -->
{% block content1 %}
<h2>생산관리 리스트</h2>
<table>
  <thead>
    <tr>
      <td><B>생산번호</B></td>
      <td><B>수주번호(수주아이템)</B></td>
      <td><B>관리번호</B></td>
      <td><B>생산품명</B></td>
      <td><B>생산수량</B></td>
      <td><B>생산지시자</B></td>
      <td><B>생산지시일</B></td>
      <td><B>생산지시서출력</B></td>
    </tr>
  </thead>

  <tbody>
    {% for production in productions %}
    <tr>
      <td>{{ production.pd_id }}</td>
      <td>{{ production.sales_id }}</td>
      <td>{{ production.uniq_id }}</td>
      <td><a href="{% url 'index_production_detail' production.pk %}">{{ production.pd_item }}</a></td>
      <td>{{ production.pd_input }}</td>
      <td>{{ production.author }}</td>
      <td>{{ production.created_at }}</td>
      <td><a href="#" target='_blank'>Go!</a></td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endblock %}
<!-- End Main block -->

<!--navbar_sub  -->
{% block navbar_sub %}
{% include "navbar_sub.html" %}
{% endblock %}

<!-- Sub block -->
{% block content2 %}
<h2>수정하기</h2>
<table>
  <thead>
    <tr>
      <td><B>수주번호(수주아이템)</B></td>
      <td><B>관리번호</B></td>
      <td><B>생산품명</B></td>
      <td><B>생산수량</B></td>
      <td><B>생산지시자</B></td>
    </tr>
  </thead>

  <tbody>
    <tr>
      <form method="post">
        {% csrf_token %}
        {% for form_td in form %}
        <td>{{ form_td }}</td>
        {% endfor %}
        <a href="{% url 'index_production' %}"><button type="submit">수정</button></a>
      </form>
    </tr>
  </tbody>
</table>
{% endblock %}

{SublimeText}production/templates/production_new.html

{% extends 'base.html' %}
<!--navbar_top  -->
{% block navbar_top %}
{% include "navbar_main.html" %}
{% include "navbar_production.html" %}
{% endblock %}

<!-- Main block -->
{% block content1 %}
<h2>생산관리 리스트</h2>
<table>
  <thead>
    <tr>
      <td><B>생산번호</B></td>
      <td><B>수주번호(수주아이템)</B></td>
      <td><B>관리번호</B></td>
      <td><B>생산품명</B></td>
      <td><B>생산수량</B></td>
      <td><B>생산지시자</B></td>
      <td><B>생산지시일</B></td>
      <td><B>생산지시서출력</B></td>
    </tr>
  </thead>

  <tbody>
    {% for production in productions %}
    <tr>
      <td>{{ production.pd_id }}</td>
      <td>{{ production.sales_id }}</td>
      <td>{{ production.uniq_id }}</td>
      <td><a href="{% url 'index_production_detail' production.pk %}">{{ production.pd_item }}</a></td>
      <td>{{ production.pd_input }}</td>
      <td>{{ production.author }}</td>
      <td>{{ production.created_at }}</td>
      <td><a href="#" target='_blank'>Go!</a></td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endblock %}
<!-- End Main block -->

<!--navbar_sub  -->
{% block navbar_sub %}
{% include "navbar_sub.html" %}
{% endblock %}

<!-- Sub block -->
{% block content2 %}
<h2>새글작성하기</h2>
<table>
  <thead>
    <tr>
      <td><B>수주번호(수주아이템)</B></td>
      <td><B>관리번호</B></td>
      <td><B>생산품명</B></td>
      <td><B>생산수량</B></td>
      <td><B>생산지시자</B></td>
    </tr>
  </thead>

  <tbody>
    <tr>
      <form method="post">
        {% csrf_token %}
        {% for form_td in form %}
        <td>{{ form_td }}</td>
        {% endfor %}
        <a href="{% url 'index_production' %}"><button type="submit">생성</button></a>
      </form>
    </tr>
  </tbody>
</table>
{% endblock %}

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
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
글 보관함