I'm thinking of using django-select2 project on my forms, but I'm mostly concerned about views do they have to be class-based views or I can use regular function views ? In the documentation they only mention class-based views but didn't say a word about function based views (like in snippet below) so I don't know if it will work with my regular function views? Thanks in advance.
https://django-select2.readthedocs.io/en/latest/
A simple class based view will do, to render your form:
# views.py
from django.views import generic
from . import forms, models
class BookCreateView(generic.CreateView):
model = models.Book
form_class = forms.BookForm
success_url = "/"
And I want to use it with the view like one below is:
def prilog_tacka_poziv_dodaj(request,poziv_id,tackapoziv_id):
poziv=Poziv.objects.get(id=poziv_id)
tackapoziv=TackaPoziv.objects.get(id=tackapoziv_id)
if request.method=='POST':
forma=PrilogTackaPozivDodaj(request.POST)
if forma.is_valid():
forma.save()
return redirect('poziv',poziv_id=poziv.id)
else:
forma=PrilogTackaPozivDodaj(initial={'tacka_poziv':tackapoziv})
return render(request,'prilog_tacka_poziv_dodaj.html',{'forma':forma,'poziv':poziv,'tackapoziv':tackapoziv})
I have tried it and it works with function based views also!