일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- channels
- Python
- qpa_plugin
- django erp
- django
- query 최적화
- django test
- 페이지 최적화
- materialized
- django role based
- pip 설치
- 재고 관리
- pip 오류
- tensorflow
- optimization page
- pyside6
- 장고로 ERP
- 중량 관리
- pyside6 ui
- QApplication
- 파이썬
- django drf
- ERP
- orm 최적화
- test drive development
- Self ERP
- 장고
- django rank
- qwindows.dll
- uiload
- Today
- Total
취미삼아 배우는 프로그래밍
토이 프로젝트) 생산관리 시스템 본문
내가 사용하기 위해 만들 시스템을
아직도 만들고 있다.
사실 전에 만들던게 있는데 너무 코드가 더럽게 꼬여서 v2라 하고 다시 새롭게 만들고 있다.
그 중간에 다른 토이프로젝트를 진행하긴 했었다.
1. 원자재관리(소요기간 한 달)
어떻게보면 이거 하면서 실력이 조금 붙은거 같다.
자잘자잘한 기능이 엄청 많이 필요하기도 했고,
만들어달라는 사람이 이거 이렇게 만들어줘 말만 던져놓고
2주차때 갑자기 이거아니야 해서 다시 모델부터 뜯어고쳤다.
그래서 엄청 고생했었다.
근데 지금 코드를 보고 보수를 하려하면
차라리 다시 짜는게 훨씬 빠를지도 모르겠다
CHANNELS 웹소켓을 사용하려다보니 자바스크립트 떡칠이 너무 심하다..
리액트를 조금만 더 잘 다룬다면 리액트로 쫙 핥을텐데,,
2. 반출 관리 시스템(소요기간 5시간+2시간(뒤처리))
어쩌다 만들게 됐냐면
우리 외국인 친구가 차량에 상차를 하면 매번 쪽지로 전달해준다
만약 10다발이면
10다발 무게 다 적어서주는데,, 나는 그걸 다 더해야 했다....
하나하나.. 전화받으믄서...
이거 숫자를 다 더하는게 바쁠때 정말 너무 귀찮아서
잠깐 시간내서 만들었는데 생각보다 괜찮게 쓰고있다.
3. 자체 데이터 검색기(소요기간 2시간 반)
아무래도 기업에서 ERP를 제대로 안만들다보니
데이터를 매번 엑셀로 축적하게 된다.
근데 데이터를 엑셀에서 매번 찾는다..?
으.. 극혐
그래서 만들었고, 월 마감할 때 요긴하게 쓰였다.
중간중간에 다른것들을 만들어보기도 했는데, 그중 이 세개가 제일 사용빈도가 높은거 같다.
그리고 이 경험을 토대로 다시 이전에 중단했었던
생산관리 시스템을 만들어볼거다.
4. 생산관리 시스템 만드는중(구상해 둔 볼륨이 좀 큼)
크..
리액트로 프론트를 짜보고 싶었지만,
그냥 장고 템플릿으로 떼우는게 일단은 더 빠를것 같다.
def main_view(request):
queryset = wall_list_model.objects.all()
table = WallMainTable(queryset)
table.paginate(page=request.GET.get("page", 1), per_page=5)
# print(table.standard_wall_counts)
context = {
'table':table,
# 'wall_count':table.standard_wall_counts,
}
template = 'wall/wall_table_view.html'
return render(request,template,context)
위의 메인 뷰 부분이다.
코드가 되게 간결해졌다..
왜냐면 모든 테이블 관련 부분을
Django-tables2를 사용한 테이블 클래스로 밀어버렸기 때문이다.(정말편하다..)
아래는 테이블 관련 코드다
import django_tables2 as tables
from .models import wall_list_model, wall_detailed_info
from ..models import base_loc_information
from django.utils.safestring import mark_safe
import json
# cancel_button = tables.Column(empty_values=(), verbose_name="취소 버튼")
# def render_cancel_button(self, value, record):
# return format_html(create_action_button(record,'취소'))
# <a class="btn tooltipped" data-position="bottom" data-tooltip="I am a tooltip">Hover me!</a>
# <i class="material-icons">check</i> clear
class WallMainTable(tables.Table):
company_name = tables.Column(accessor='base_info.company_name', verbose_name="업체명")
location_name = tables.Column(accessor='base_info.location_name', verbose_name='현장명')
process_check = tables.Column(empty_values=(), verbose_name="진행상황")
# standard_wall_counts = []
class Meta:
model = wall_list_model
template_name = "wall/materialized_table.html"
sequence = ('submitdate', 'company_name', 'location_name',
'district_category', 'creatings', 'coatings',
'addings_manufacturing', 'standard_count', 'process_check',
'standard_complete_chk','standard_go_to_location',
'nonstandard_go_to_location', 'notes' )
exclude = ('base_info', 'id',
'non_standard_coat_complete_chk',
'non_standard_manufacturing_chk',
'non_standard_outing_chk',
'addings_complete_chk',
# 'standard_complete_chk',
)
def render_standard_complete_chk(self,value, record):
return mark_safe(to_chk_box(value, record))
def render_addings_manufacturing(self,value, record):
return mark_safe(to_chk_box(value, record))
def render_standard_go_to_location(self, value, record):
return mark_safe(to_chk_box(value, record))
def render_nonstandard_go_to_location(self, value, record):
return mark_safe(to_chk_box(value, record))
def render_process_check(self, value, record):
return mark_safe(process_phrase(value,record))
def render_standard_count(self, value, record):
# render_value = {}
# render_value['id'] = record.id
# render_value['content'] = json.loads(value)
# self.standard_wall_counts.append(render_value)
return mark_safe(standard_wall_count_btn(value, record))
def chk_helper(val):
if(val):
return '<i class="material-icons">check</i>'
else:
return '<i class="material-icons">clear</i>'
def tooltip_helper(val):
if(val):
return
else:
return
def process_phrase(value, record):
step1 = record.non_standard_manufacturing_chk
step2 = record.non_standard_outing_chk
step3 = record.addings_complete_chk
step4 = record.non_standard_coat_complete_chk
step = [step1, step2, step3, step4]
step = [chk_helper(i) for i in step]
# f'mmmmmmm{ "aaa" if aa else ""}'
no_message = "NO"
yes_message = "YES"
tooltip = f"""
비규격용접절단: { yes_message if step1 else no_message }<br>
비규격반출: { yes_message if step2 else no_message }<br>
서진덧방: { yes_message if step3 else no_message }<br>
비규격코팅: { yes_message if step4 else no_message }<br>
"""
phrase = " ".join(step)
btn = f'<a class="btn tooltipped" data-position="top" data-tooltip="{tooltip}">{phrase}</a>'
return btn
def standard_wall_count_btn(value, record):
btn = f'<a class="waves-effect waves-light btn modal-trigger" href="#modal{record.id}">Modal</a>'
btn += f'''
<!-- Modal Structure -->
<div id="modal{record.id}" class="modal">
<div class="modal-content">
<h4>Modal Header</h4>
<p>{value}</p>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-green btn-flat">Agree</a>
</div>
</div>
'''
return btn
def to_chk_box(value, record):
bool_value = None
if value:
bool_value = 'checked="checked"'
text = f"""
<label>
<input type="checkbox" {bool_value} disabled="disabled" />
<span></span>
</label>
"""
return text
이전 코드에선 모든 데이터들을 프론트페이지쪽으로 보내고
그 데이터들을 알아서 프론트페이지쪽에서 짜집기해서 테이블을 만들고 구성하는 방법이었다.
어떻게 보면 가장 원초적인 접근이었는데, 지금 생각해도 굉장히 야만적이고 무식한 방법이었다.
왜냐면, 모델을 하나 추가할 때마다 매번 프론트 페이지를 바꿔줘야 했고,
이 안의 HTML만 바꾸면 다행인데, 자바스크립트까지 건드려야 하는 경우가 대다수였더랬다.
생각만해도 끔찍하다. 하나를 수정하면 잔뿌리 5개를 찾아서 수정해야한다니..
그런데 지금의 방법은 그냥 서버에서 계산된 HTML을 뿌려주기 때문에 일단 코드 자체는 더욱 간결하면서
필요한 곳에 딱딱 들어간다.(서버 부하는 조금 늘겠지만, 나한테 부하가 생기는거보다는 괜찮지 않을까? 부하가 생겨서 부아가 치밈)
따로들어가는 컴포넌트는
툴팁을 보여주는 버튼과
모달페이지를 띄우는 버튼을 넣었다.
특이한건 모달페이지는 < td > 안에 있어도
바깥에 있는것 마냥 작동되는 거였는데, 밖에 있는것만 됐더라면 상당히 골치아플 수도 있었다.
이걸 가능하게 해준게 django_tables2다.
모델이 바뀌면 테이블이 바뀐다
크.. 혁명 그 자체
이게 키 라이브러리였다.
어느정도 커스텀까지 각이 나왔다.
의 테이블은 사실 Materialized css 를 사용한 결과물이다.
원래대로라면 컬럼 이름에 링크가 죄다 붙어있다.
이게 커스텀을 해주려면
django_tables2 라이브러리 내 Materialized css를 사용하는 템플릿이 없기 때문에 따로 작성해주어야 했는데
생각보다 간단한 방법이 있었다.
그냥 라이브러리내 기본 템플릿을 땡겨와서 입맛에 맞게 커스텀만 해주면 되는거였다..
테이블라이브러리 만든사람 갓갓..
{% load django_tables2 %}
{% load i18n %}
{% block table-wrapper %}
<div class="table-container">
{% block table %}
<table {% render_attrs table.attrs class="table striped centered" %}>
{% block table.thead %}
{% if table.show_header %}
<thead {{ table.attrs.thead.as_html }}>
<tr>
{% for column in table.columns %}
<th {{ column.attrs.th.as_html }}>
{% if column.orderable %}
{# <a href="{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}">{{ column.header }}</a> #}
{{ column.header }}
{% else %}
{{ column.header }}
{% endif %}
</th>
{% endfor %}
</tr>
</thead>
{% endif %}
{% endblock table.thead %}
{% block table.tbody %}
<tbody {{ table.attrs.tbody.as_html }}>
{% for row in table.paginated_rows %}
{% block table.tbody.row %}
<tr {{ row.attrs.as_html }}>
{% for column, cell in row.items %}
<td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td>
{% endfor %}
</tr>
{% endblock table.tbody.row %}
{% empty %}
{% if table.empty_text %}
{% block table.tbody.empty_text %}
<tr><td colspan="{{ table.columns|length }}">{{ table.empty_text }}</td></tr>
{% endblock table.tbody.empty_text %}
{% endif %}
{% endfor %}
</tbody>
{% endblock table.tbody %}
{% block table.tfoot %}
{% if table.has_footer %}
<tfoot {{ table.attrs.tfoot.as_html }}>
<tr>
{% for column in table.columns %}
<td {{ column.attrs.tf.as_html }}>{{ column.footer }}</td>
{% endfor %}
</tr>
</tfoot>
{% endif %}
{% endblock table.tfoot %}
</table>
{% endblock table %}
{% block pagination %}
{% if table.page and table.paginator.num_pages > 1 %}
<ul class="pagination">
{% if table.page.has_previous %}
{% block pagination.previous %}
<li class="previous">
<li class="waves-effect"><a href="{% querystring table.prefixed_page_field=table.page.previous_page_number %}"><i class="material-icons">chevron_left</i></a></li>
</a>
</li>
{% endblock pagination.previous %}
{% endif %}
{% if table.page.has_previous or table.page.has_next %}
{% block pagination.range %}
{% for p in table.page|table_page_range:table.paginator %}
<li {% if p == table.page.number %}class="active"{% endif %}>
{% if p == '...' %}
<a href="#">{{ p }}</a>
{% else %}
<a href="{% querystring table.prefixed_page_field=p %}">
{{ p }}
</a>
{% endif %}
</li>
{% endfor %}
{% endblock pagination.range %}
{% endif %}
{% if table.page.has_next %}
{% block pagination.next %}
<li class="next">
<li class="waves-effect"><a href="{% querystring table.prefixed_page_field=table.page.next_page_number %}"><i class="material-icons">chevron_right</i></a></li>
</a>
</li>
{% endblock pagination.next %}
{% endif %}
</ul>
{% endif %}
{% endblock pagination %}
</div>
{% endblock table-wrapper %}
그렇게 해서 땡긴게 위의 코드인데,
사실 별건없고
- Pagination 부분을 Materialized css의 것에 맞게 수정
- 테이블 기본 클래스 네임 수정
만 해준 부분이다.
'코드 자가리뷰(장고)' 카테고리의 다른 글
초등학교 게시판 만들기 -3 (0) | 2020.04.23 |
---|---|
초등학교 학교게시판 만들기. (0) | 2020.04.19 |
초등학교 학교게시판 만들기 (0) | 2020.04.18 |
django-tables 작성에 관한 고찰 (0) | 2020.03.30 |
토이프로젝트) 생산관리 시스템 - 폼 작성 (0) | 2020.03.12 |