.
This commit is contained in:
+2
-2
@@ -9,7 +9,7 @@ from .models import (
|
||||
Modality,
|
||||
Region,
|
||||
BodyPart,
|
||||
Structure,
|
||||
Structure2,
|
||||
)
|
||||
|
||||
from generic.models import Examination
|
||||
@@ -59,5 +59,5 @@ admin.site.register(Exam, ExamAdmin)
|
||||
admin.site.register(Modality)
|
||||
admin.site.register(Region)
|
||||
admin.site.register(BodyPart)
|
||||
admin.site.register(Structure)
|
||||
admin.site.register(Structure2)
|
||||
|
||||
|
||||
+7
-7
@@ -14,7 +14,7 @@ from .models import (
|
||||
AnatomyQuestion,
|
||||
#Examination,
|
||||
BodyPart,
|
||||
Structure,
|
||||
Structure2,
|
||||
Region,
|
||||
Modality,
|
||||
QuestionType,
|
||||
@@ -86,7 +86,7 @@ class AnatomyQuestionForm(ModelForm):
|
||||
queryset=Modality.objects.all(),
|
||||
)
|
||||
|
||||
#self.fields["structure"] = ModelChoiceField(
|
||||
#self.fields["Structure2"] = ModelChoiceField(
|
||||
# required=False,
|
||||
# queryset=Structure.objects.all(),
|
||||
#)
|
||||
@@ -148,7 +148,7 @@ class AnatomyQuestionForm(ModelForm):
|
||||
"image",
|
||||
"region",
|
||||
"modality",
|
||||
"structure",
|
||||
"Structure2",
|
||||
"examination",
|
||||
"body_part",
|
||||
"description",
|
||||
@@ -156,7 +156,7 @@ class AnatomyQuestionForm(ModelForm):
|
||||
]
|
||||
|
||||
widgets = {
|
||||
"structure" : autocomplete.ModelSelect2(url='anatomy:structure-autocomplete')
|
||||
"Structure2" : autocomplete.ModelSelect2(url='anatomy:Structure2-autocomplete')
|
||||
}
|
||||
|
||||
|
||||
@@ -197,10 +197,10 @@ class ExaminationForm(ModelForm):
|
||||
fields = ["examination"]
|
||||
|
||||
|
||||
class StructureForm(ModelForm):
|
||||
class Structure2Form(ModelForm):
|
||||
class Meta:
|
||||
model = Structure
|
||||
fields = ["structure"]
|
||||
model = Structure2
|
||||
fields = ["Structure2"]
|
||||
|
||||
|
||||
class BodyPartForm(ModelForm):
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# Generated by Django 3.2.8 on 2021-10-25 10:02
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('anatomy', '0047_auto_20211022_2038'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Structure2',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('structure', models.CharField(max_length=200, unique=True)),
|
||||
],
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='anatomyquestion',
|
||||
name='structure',
|
||||
field=models.CharField(max_length=255, null=True),
|
||||
),
|
||||
]
|
||||
+10
-2
@@ -48,6 +48,11 @@ class Structure(models.Model):
|
||||
def __str__(self):
|
||||
return self.structure
|
||||
|
||||
class Structure2(models.Model):
|
||||
structure = models.CharField(max_length=200, unique=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.structure
|
||||
|
||||
class Region(models.Model):
|
||||
region = models.CharField(max_length=200)
|
||||
@@ -110,8 +115,11 @@ class AnatomyQuestion(models.Model):
|
||||
body_part = models.ForeignKey(
|
||||
BodyPart, on_delete=models.SET_NULL, null=True, blank=True
|
||||
)
|
||||
structure = models.ForeignKey(
|
||||
Structure, on_delete=models.SET_NULL, null=True, blank=True
|
||||
#structure = models.ForeignKey(
|
||||
# Structure, on_delete=models.SET_NULL, null=True, blank=True
|
||||
#)
|
||||
structure = models.CharField(
|
||||
max_length=255, null=True
|
||||
)
|
||||
created_date = models.DateTimeField(default=timezone.now)
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
from django.urls import path, include
|
||||
|
||||
from anatomy.models import Structure
|
||||
from anatomy.models import Structure2
|
||||
from . import views
|
||||
from django.views.decorators.cache import cache_page
|
||||
|
||||
@@ -151,7 +151,7 @@ urlpatterns = [
|
||||
),
|
||||
path(
|
||||
"structure-autocomplete",
|
||||
views.StructureAutocomplete.as_view(model=Structure, create_field='structure'),
|
||||
views.Structure2Autocomplete.as_view(model=Structure2, create_field='structure'),
|
||||
name="structure-autocomplete",
|
||||
),
|
||||
]
|
||||
|
||||
+9
-9
@@ -34,7 +34,7 @@ from .forms import (
|
||||
ExaminationForm,
|
||||
MarkAnatomyQuestionForm,
|
||||
AnatomyQuestionForm,
|
||||
StructureForm,
|
||||
Structure2Form,
|
||||
ExamForm,
|
||||
)
|
||||
from .models import (
|
||||
@@ -42,7 +42,7 @@ from .models import (
|
||||
BodyPart,
|
||||
CidUserAnswer,
|
||||
# Examination,
|
||||
Structure,
|
||||
Structure2,
|
||||
Exam,
|
||||
Answer,
|
||||
# HalfMarkAnswers,
|
||||
@@ -872,7 +872,7 @@ def get_examination_id(request):
|
||||
|
||||
@login_required
|
||||
def create_structure(request):
|
||||
form = StructureForm(request.POST or None)
|
||||
form = Structure2Form(request.POST or None)
|
||||
if form.is_valid():
|
||||
instance = form.save()
|
||||
return HttpResponse(
|
||||
@@ -880,7 +880,7 @@ def create_structure(request):
|
||||
% (instance.pk, instance)
|
||||
)
|
||||
return render(
|
||||
request, "anatomy/create_simple.html", {"form": form, "name": "Structure"}
|
||||
request, "anatomy/create_simple.html", {"form": form, "name": "Structure2"}
|
||||
)
|
||||
|
||||
|
||||
@@ -888,7 +888,7 @@ def create_structure(request):
|
||||
def get_structure_id(request):
|
||||
if request.is_ajax():
|
||||
structure_name = request.GET["structure_name"]
|
||||
structure_id = Structure.objects.get(name=structure_name).id
|
||||
structure_id = Structure2.objects.get(name=structure_name).id
|
||||
data = {
|
||||
"structure_id": structure_id,
|
||||
}
|
||||
@@ -1003,20 +1003,20 @@ class ExamClone(ExamCloneMixin, ExamCreate):
|
||||
"""Clone exam view"""
|
||||
|
||||
|
||||
class StructureAutocomplete(autocomplete.Select2QuerySetView):
|
||||
class Structure2Autocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
# Don't forget to filter out results depending on the visitor !
|
||||
if not self.request.user.is_authenticated:
|
||||
return Structure.objects.none()
|
||||
return Structure2.objects.none()
|
||||
|
||||
qs = Structure.objects.all()
|
||||
qs = Structure2.objects.all()
|
||||
|
||||
if self.q:
|
||||
# This raises a fielderror which breaks creating a new item if not caught
|
||||
try:
|
||||
qs = qs.filter(name__istartswith=self.q)
|
||||
except FieldError:
|
||||
return Structure.objects.none()
|
||||
return Structure2.objects.none()
|
||||
|
||||
|
||||
return qs
|
||||
|
||||
Reference in New Issue
Block a user