@permission_required("core.manage_shop")
def assign_products(request, discount_id):
    discount = lfs_get_object_or_404(Discount, pk=discount_id)

    for temp_id in request.POST.keys():
        if temp_id.startswith("product"):
            temp_id = temp_id.split("-")[1]
            product = Product.objects.get(pk=temp_id)
            discount.products.add(product)

    html = [["#products-inline", products_inline(request, discount_id, as_string=True)]]
    result = json.dumps({
        "html": html,
        "message": _(u"Products have been assigned.")
    }, cls=LazyEncoder)

    return HttpResponse(result, content_type='application/json')
Assign products to given property group with given property_group_id.
dataset/ETHPy150Open diefenbach/django-lfs/lfs/manage/discounts/views.py/assign_products