프론트 / 백엔드 진행 상황 공유 및 오늘 할 일
<프론트>
<백엔드>
before
{"results": [
{"product_id": 1,
"quantity" :4,
"product_option_id": "",
"product_option_quantity":0
}]
}
after
{"product_id": 1,
"quantity" :4,
"product_option_id": "",
"product_option_quantity":0
}
이에 따른 적절한 코드는 다음과 같다.
before
class WishListView(View):
@auth_check
@transaction.atomic
def post(self, request):
try:
results = json.loads(request.body)['results']
user_id = request.user.id
for result in results:
product_id = result['product_id']
quantity = result['quantity']
product_option_id = result['product_option_id']
product_option_quantity = result['product_option_quantity']
after
class WishListView(View):
@auth_check
@transaction.atomic
def post(self, request):
try:
data = json.loads(request.body)
user_id = request.user.id
product_id = data['product_id']
quantity = data['quantity']
product_option_id = data['product_option_id']
product_option_quantity = data['product_option_quantity']
result = []
for i in user_coupon_list:
if i in sub_category_coupon_list:
result.append(i)
coupon_name = []
for j in result:
coupon = Coupon.objects.get(id=j)
coupon_name.append(coupon.name)
coupon_name = [Coupon.objects.get(id=j).name for j in [i for i in user_coupon_list if i in sub_category_coupon_list]]
coupon = Coupon.objects.get(name=data['name'])
# 먼저 쿠폰을 가져오고(만들어진 것)
sub_categories = SubCategory.objects.filter(name__in=data['sub_category_name'])
# name__in : 서브카테고리 객체를 네임으로 필터링할 때 프론트로부터 받아온느 제이슨 데이터 형태가 리스트일 때 쓰는 방식
for sub_category in sub_categories:
coupon_sub_category = CouponSubCategory.objects.create(
coupon=coupon,
sub_category=sub_category
)
{
"name" : "쿠폰4",
"discount_price" : 4000,
"issue_date" : "2021-03-20",
"expire_date" : "2022-03-19",
"sub_category_name" : ["신발"]
}
- 여기서 신발, 양말 등 여러 리스트 형태로 와도 잘 입력된다.
version 문제 였음.(5.26 < 8.22)