.
This commit is contained in:
Executable
+22
@@ -0,0 +1,22 @@
|
||||
from django.forms import (
|
||||
Form,
|
||||
ModelForm,
|
||||
ModelMultipleChoiceField,
|
||||
ModelChoiceField,
|
||||
ChoiceField,
|
||||
CharField,
|
||||
)
|
||||
from django.forms import inlineformset_factory
|
||||
|
||||
from generic.models import (
|
||||
Examination,
|
||||
)
|
||||
|
||||
from django.contrib.admin.widgets import FilteredSelectMultiple
|
||||
from django.forms.widgets import RadioSelect, TextInput, Textarea
|
||||
|
||||
|
||||
class ExaminationForm(ModelForm):
|
||||
class Meta:
|
||||
model = Examination
|
||||
fields = ["examination"]
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
from django.urls import path, include
|
||||
from . import views
|
||||
|
||||
app_name = "generic"
|
||||
|
||||
urlpatterns = [
|
||||
# path('', views.question_list, name='question_list'),
|
||||
path("examination/create/",
|
||||
views.create_examination,
|
||||
name="create_examination"),
|
||||
path("examination/ajax/get_examination_id",
|
||||
views.get_examination_id,
|
||||
name="get_examination_id"),
|
||||
]
|
||||
@@ -1,3 +1,27 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
@login_required
|
||||
def create_examination(request):
|
||||
form = ExaminationForm(request.POST or None)
|
||||
if form.is_valid():
|
||||
instance = form.save()
|
||||
return HttpResponse(
|
||||
'<script>opener.closePopup(window, "%s", "%s", "#id_examination");</script>'
|
||||
% (instance.pk, instance)
|
||||
)
|
||||
return render(
|
||||
request, "rapids/create_simple.html", {"form": form, "name": "Examination"}
|
||||
)
|
||||
|
||||
@csrf_exempt
|
||||
def get_examination_id(request):
|
||||
if request.is_ajax():
|
||||
examination_name = request.GET["examination_name"]
|
||||
examination_id = Examination.objects.get(name=examination_name).id
|
||||
data = {
|
||||
"examination_id": examination_id,
|
||||
}
|
||||
return HttpResponse(json.dumps(data), content_type="application/json")
|
||||
return HttpResponse("/")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user