django imagefield modelform

Solutions on MaxInterview for django imagefield modelform by the best coders in the world

showing results for - "django imagefield modelform"
Cierra
06 May 2016
1@login_required
2def Product_Adder_View(request):
3    
4    if request.method == 'POST':
5        Prdct_form = ProductForm(request.POST, request.FILES)
6        if Prdct_form.is_valid():
7            Prdct_form.save()
8            return HttpResponseRedirect(reverse('basic_app:Product_added'))
9        else:
10            raise('Not Valid Form')
11    else:
12        Prdct_form = ProductForm()
13    return render(request, 'basic_app/product_adding.html', context={'Prdct_form':Prdct_form})
14  
15  
16  # in form ModelForm
17  class ProductForm(forms.ModelForm):
18    # category = forms.ModelChoiceField(queryset= PCategory.order_by('cat_name'))
19    category = forms.ModelChoiceField(queryset= PCategory.objects.all())
20    product_image = forms.ImageField()
21    class Meta:
22        model = Products
23        fields = ("category", "product_name", "product_image")
24