예제 #1
0
def add_product(request):
    params = json.loads(request.POST['json'])

    name = params['name']
    price = params['precio']
    description = params['description']
    date_up = datetime.now()

    if not name:
        return JsonResponse({}, status=400)

    product = Products()
    product.name = name
    product.description = description
    product.price = price
    product.date_up = date_up
    product.save()

    response = {
        'created': True
    }
    return JsonResponse(response, status=200)
예제 #2
0
#在manage.py中
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "beenquickServer.settings")

import django
django.setup()

from db_tools.axf_json import JSONSTR
from products.models import Products

data = eval(JSONSTR)['data']
products = data['products']
for k, v in products.items():
    for product in v:
        p = Products()
        p.id = product['id']
        p.name = product['name']
        p.longname = product['long_name']
        p.store_nums = product['store_nums']
        p.specifics = product['specifics']
        p.attribute = product['attribute']
        p.sort = product['sort']
        p.brand_id = product['brand_id']
        p.brand_name = product['brand_name']
        p.hot_degree = product['hot_degree']
        p.safe_day = product['safe_day']
        p.safe_unit = product['safe_unit']
        p.market_price = product['market_price']
        p.partner_price = product['partner_price']
        p.pre_img = product['pre_img']
        p.pre_imgs = product['pre_imgs']
        p.keywords = product['keywords']