Exemplo n.º 1
0
def attribute_del(id):
    try:
        attr = ProductAttribute.get_by_id(id)
        attr.delete()
    except Exception as e:
        return ApiResult({"r": 1, "msg": str(e)})
    return ApiResult(dict())
Exemplo n.º 2
0
def attribute_manage(id=None):
    if id:
        attr = ProductAttribute.get_by_id(id)
        form = AttributeForm(obj=attr)
    else:
        form = AttributeForm()
    if form.validate_on_submit():
        if not id:
            attr = ProductAttribute()
        attr.title = form.title.data
        attr.update_types(form.types.data)
        attr.update_values(form.values.data)
        attr.save()
        return redirect(url_for("dashboard.attributes"))
    product_types = ProductType.query.all()
    return render_template(
        "product/attribute.html", form=form, product_types=product_types
    )
Exemplo n.º 3
0
def create_attributes_and_values(attribute_data):
    attributes = []
    for attribute_name, attribute_values in attribute_data.items():
        attribute, _ = ProductAttribute.get_or_create(title=attribute_name)
        for value in attribute_values:
            defaults = {"attribute_id": attribute.id, "title": value}
            AttributeChoiceValue.get_or_create(**defaults)
        attributes.append(attribute)
    return attributes