21👍
✅
save
is available only for ModelForm
by default, and not for forms.Form
What you need to do is this. Either use:
class AdvancedSearchForm(forms.ModelForm):
valueofres = forms.ChoiceField (label="res", choices = ((0, 0),(2.2, 2.2)), required= False)
class Meta:
model=Search #or whatever object
Or:
def advancedsearch(request):
if request.method == "POST":
search_form = AdvancedSearchForm(request.POST, request.FILES)
if search_form.is_valid():
cd = search_form.cleaned_data
search = #populate SearchObject()
search.save()
9👍
Form
s don’t have a save()
method.
You need to use a ModelForm
(docs) as that will then have a model
associated with it and will know what to save where.
Alternatively you can keep your forms.Form
but you’ll want to then extract the valid data from the for and do as you will with eh data.
if request.method == "POST":
search_form = AdvancedSearchForm(request.POST, request.FILES)
if search_form.is_valid():
cd = search_form.cleaned_data
search = Search(
# Apply form data
)
search.save()
- Use slugify in template
- Is there a Django template tag that lets me set a context variable?
- Sending a message to a single user using django-channels
- Django's get_current_language always returns "en"
- There are errors when I install django by git?
Source:stackexchange.com