Skip to content

Commit c028aa0

Browse files
authored
Merge pull request #184 from pirogramming/develop
[DB] 가격이랑 제조사 모델 수정
2 parents af25e5b + 722ff84 commit c028aa0

File tree

9 files changed

+68
-15
lines changed

9 files changed

+68
-15
lines changed

foods/admin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
@admin.register(Food)
66
class FoodAdmin(admin.ModelAdmin):
7-
list_display = ['food_id', 'food_name', 'company_name', 'food_category', 'shop_name', 'price']
8-
list_filter = ['food_category', 'company_name', 'shop_name']
7+
list_display = ['food_id', 'food_name', 'company_name', 'food_category', 'mallName', 'lprice']
8+
list_filter = ['food_category', 'company_name', 'mallName']
99
search_fields = ['food_name', 'company_name', 'representative_food']
1010
readonly_fields = ['food_id']
1111

@@ -29,7 +29,7 @@ class FoodAdmin(admin.ModelAdmin):
2929
'classes': ('collapse',)
3030
}),
3131
('가격 정보', {
32-
'fields': ('shop_name', 'price', 'discount_price', 'shop_url', 'image_url'),
32+
'fields': ('mallName', 'lprice', 'discount_price', 'shop_url', 'image_url'),
3333
'classes': ('collapse',)
3434
}),
3535
('기타 정보', {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.4 on 2025-08-17 22:12
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('foods', '0007_food_nrf_index_food_nutri_score_grade_and_more'),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name='food',
15+
old_name='price',
16+
new_name='lprice',
17+
),
18+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.4 on 2025-08-17 22:13
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('foods', '0008_rename_price_food_lprice'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='food',
15+
name='mallName',
16+
field=models.CharField(blank=True, max_length=100, null=True),
17+
),
18+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 5.2.4 on 2025-08-17 22:14
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('foods', '0009_food_mallname'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='food',
15+
name='shop_name',
16+
),
17+
]

foods/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class Food(models.Model):
5151
nrf_index = models.FloatField(null=True, blank=True)
5252

5353
# 가격 정보 (CSV 칼럼에 맞춰 추가)
54-
shop_name = models.CharField(max_length=100, null=True, blank=True)
55-
price = models.BigIntegerField(null=True, blank=True)
54+
lprice = models.BigIntegerField(null=True, blank=True) # 네이버 쇼핑 최저가
5655
discount_price = models.BigIntegerField(null=True, blank=True)
56+
mallName = models.CharField(max_length=100, null=True, blank=True) # 쇼핑몰 이름
5757
shop_url = models.URLField(null=True, blank=True)
5858
image_url = models.URLField(null=True, blank=True)
5959

products/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ def _product_dict(food, is_favorite: bool):
3535
"trans_fatty_acids": food.trans_fatty_acids,
3636
"nutritional_value_standard_amount": food.nutritional_value_standard_amount,
3737
"weight": food.weight,
38-
"company_name": food.shop_name or food.company_name,
38+
"company_name": food.mallName or food.company_name,
3939
"nutrition_score": food.nutrition_score,
4040
"nutri_score_grade": food.nutri_score_grade,
41-
"price": food.price,
42-
"shop_name": food.shop_name,
41+
"lprice": food.lprice,
42+
"shop_name": food.mallName,
4343
"shop_url": food.shop_url,
4444
"sugar_level": None,
4545
"saturated_fatty_acids_level": None,

scripts/insert_food_postgresql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def main():
149149
csv_to_db = {
150150
'food_id': 'food_id',
151151
'mallName': 'shop_name',
152-
'lprice': 'price',
152+
'lprice': 'lprice',
153153
'hprice': 'discount_price',
154154
'shop_url': 'shop_url',
155155
'image_url': 'image_url',
@@ -215,7 +215,7 @@ def main():
215215
for c in float_cols:
216216
out[c] = out[c].apply(to_float)
217217

218-
bigint_cols = ['nutritional_value_standard_amount', 'price', 'discount_price']
218+
bigint_cols = ['nutritional_value_standard_amount', 'lprice', 'discount_price']
219219
for c in bigint_cols:
220220
out[c] = out[c].apply(to_bigint)
221221

scripts/rebuild_clean_database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ def validate_and_clean_row(args):
213213
cleaned_row[field] = value if pd.notna(value) else None
214214

215215
# 정수 필드 정리
216-
int_fields = ['nutritional_value_standard_amount', 'price', 'discount_price']
216+
int_fields = ['nutritional_value_standard_amount', 'lprice', 'discount_price']
217217
for field in int_fields:
218-
value = pd.to_numeric(row.get(field if field != 'price' else 'lprice', None), errors='coerce')
218+
value = pd.to_numeric(row.get(field if field != 'lprice' else 'lprice', None), errors='coerce')
219219
if field == 'discount_price':
220220
value = pd.to_numeric(row.get('hprice', None), errors='coerce')
221221
if field == 'nutritional_value_standard_amount':
@@ -419,7 +419,7 @@ def update_progress():
419419
'potassium','salt','"VitaminA"','"VitaminB"','"VitaminC"','"VitaminD"','"VitaminE"',
420420
'cholesterol','saturated_fatty_acids','trans_fatty_acids','serving_size',
421421
'weight','company_name','nutrition_score','nutri_score_grade','nrf_index',
422-
'shop_name','price','discount_price','shop_url','image_url'
422+
'shop_name','lprice','discount_price','shop_url','image_url'
423423
]
424424

425425
placeholders = ",".join(["%s"] * len(cols))

templates/products/products_detail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ <h3>공유하기</h3>
6969
<div class="product-title-section">
7070
<h1 class="product-name">{{ product.food_name }}</h1>
7171
<div class="product-price">
72-
{% if product.price %}
73-
{{ product.price }}<span class="currency"></span>
72+
{% if product.lprice %}
73+
{{ product.lprice }}<span class="currency"></span>
7474
{% else %}
7575
가격 정보 없음
7676
{% endif %}

0 commit comments

Comments
 (0)