Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- django rank
- django test
- tensorflow
- 페이지 최적화
- django role based
- Python
- pyside6 ui
- django drf
- optimization page
- query 최적화
- materialized
- test drive development
- django
- pip 오류
- pip 설치
- qpa_plugin
- QApplication
- channels
- 장고로 ERP
- orm 최적화
- django erp
- uiload
- 파이썬
- pyside6
- 중량 관리
- Self ERP
- ERP
- qwindows.dll
- 장고
- 재고 관리
Archives
- Today
- Total
취미삼아 배우는 프로그래밍
django-tables 작성에 관한 고찰 본문
django-tables2 앱을 활용하여 테이블을 작성했다.
생각보다 django-tables2는 커스터마이징이 쉽고 되게 편리하다.
(primary key를 이용해서 데이터 불러오는게 조금 어렵긴 한데, 그래도 되긴 된다.)
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', 'is_it_16_floor', 'is_it_BTF',
# '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):
value_obj = json.loads(value)
temp_value = 0
for rd in value_obj:
for v in rd['count']:
temp_value += int(rd['count'][v])
btn = f'<a class="waves-effect waves-light btn modal-trigger" href="#modal{record.id}"> {temp_value} 장</a>'
btn += f'''
<!-- Modal Structure -->
<div id="modal{record.id}" class="modal">
<div class="modal-content">
<h4>기본수량</h4>
<p>{mini_table_in_modal(value)}</p>
</div>
<div class="modal-footer">
<a href="#!" class="modal-close waves-effect waves-green btn-flat">확인</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
def mini_table_in_modal(value):
td_data = list()
data = json.loads(value)
base_html = '''
<table class='table striped centered mini_table' >
<tr>
<th>Fillar+PANEL+Rocker</th>
<th>300</th>
<th>400</th>
<th>450</th>
<th>600</th>
</tr>
<tbody>
'''
end_html = '''
</tbody>
</table>
'''
for row in data:
td_data.append(
f'''
<tr>
<td>{row['fillar']}+{row['base_panel']}+{row['rocker']}</td>
<td>{row['count']['300']}</td>
<td>{row['count']['400']}</td>
<td>{row['count']['450']}</td>
<td>{row['count']['600']}</td>
</tr>
'''
)
mid_html = "\n".join(td_data)
mini_table = base_html + mid_html + end_html
return mini_table
내용이 별게 없다.
테이블에 적어둔 모든 내용을 그냥 바로 보여주는 거라서 조금 더럽긴하다.
실상 구조를 보면
테이블을 생성하는것 딱 하나 있고, 나머지는 죄다 헬퍼함수다.
- 체크 부분을 바꿔줌
- 규격 수량 부분에 버튼을 추가하고 특정 값들을 모두 합해 보여줌
- 모달부분과 모달페이지를 나타내게하는 버튼을 함께 같은 td에 넣어줌(왠지모르겠지만 잘됨, 따로 밖에 빼면 안됨)
재사용은 조금 어려울 수 있지만,
생각보다 복잡한 내용의 데이터들을 깔끔하게 표핸해 낸 것 같다.
**
render_{Field_name} 는
해당 필드를 랜더링 작업하는 와중 커스텀할 때 사용한다.
acceossor는 pk를 이용한 데이터 불러오기를 할 때 사용한다.
'코드 자가리뷰(장고)' 카테고리의 다른 글
초등학교 게시판 만들기 -3 (0) | 2020.04.23 |
---|---|
초등학교 학교게시판 만들기. (0) | 2020.04.19 |
초등학교 학교게시판 만들기 (0) | 2020.04.18 |
토이프로젝트) 생산관리 시스템 - 폼 작성 (0) | 2020.03.12 |
토이 프로젝트) 생산관리 시스템 (0) | 2020.03.12 |
Comments