26 lines
1.1 KiB
Python
Executable File
26 lines
1.1 KiB
Python
Executable File
from django import forms
|
|
from django.forms import formset_factory
|
|
from .models import Offer,Offer_Category,Image_offer
|
|
from django.forms import BaseFormSet
|
|
from django.core.exceptions import ValidationError
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
class OfferCreateForm(forms.ModelForm):
|
|
title = forms.CharField(label = 'Offer title', max_length=50)
|
|
price = forms.DecimalField(min_value=0.01,max_digits=10, decimal_places=2)
|
|
class Meta:
|
|
model = Offer
|
|
fields = ('title','category','price','description','DMC','Places_to_sleep','cooker','fridge', 'microwave', 'Webasto', 'auto_temp_control', 'water_level_indicator', 'battery_level', 'photovoltaic_panels', 'gearbox', 'tempomat')
|
|
|
|
class OfferImageCreateForm(forms.ModelForm):
|
|
image = forms.ImageField(required = True)
|
|
main_image = forms.BooleanField(initial=False, required=False)
|
|
class Meta:
|
|
model = Image_offer
|
|
fields = ('image','main_image')
|
|
|
|
class BaseOfferImageFormSet(BaseFormSet):
|
|
pass
|
|
|
|
|
|
OfferImageFormSet = formset_factory(OfferImageCreateForm,formset = BaseOfferImageFormSet) |