Add open_access field to Question model and update question detail template

This commit is contained in:
Ross
2025-10-20 20:56:37 +01:00
parent ac9faeccbd
commit bdb7aff5d1
7 changed files with 71 additions and 41 deletions
+1
View File
@@ -148,6 +148,7 @@ class QuestionForm(ModelForm):
"condition",
"presentation",
"subspecialty",
"open_access",
]
widgets = {
@@ -0,0 +1,18 @@
# Generated by Django 5.1.4 on 2025-10-20 19:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sbas', '0020_question_sources'),
]
operations = [
migrations.AlterField(
model_name='question',
name='open_access',
field=models.BooleanField(default=True, help_text='If set, this question is available to all users for use in their exams.'),
),
]
+4
View File
@@ -107,6 +107,10 @@ class Question(QuestionBase):
presentation = models.ManyToManyField(Presentation, blank=True, related_name="sbas_questions")
subspecialty = models.ManyToManyField(Subspecialty, blank=True, related_name="sbas_questions")
open_access = models.BooleanField(
default=True, help_text="If set, this question is available to all users for use in their exams."
)
#notes = GenericRelation(QuestionNote)
def __str__(self):
+8
View File
@@ -149,6 +149,14 @@
{% endif %}
</div>
</div>
<div class="mb-2"><strong>Open Access:</strong>
<div>
{% if question.open_access %}
<span class="badge bg-success">Yes</span>
{% else %}
<span class="badge bg-danger">No</span>
{% endif %}
</div>
</div>
</div>
</div>
+1 -1
View File
@@ -9,7 +9,7 @@ app_name = "sbas"
urlpatterns = [
path("question/", views.QuestionView.as_view(), name="question_view"),
path("question/<int:pk>/", views.question_detail, name="question_detail"),
#path("question/<int:pk>/", views.question_detail, name="question_detail"),
path("question/create/", views.QuestionCreate.as_view(), name="question_create"),
path(
"question/<int:pk>/update",
+4 -4
View File
@@ -98,10 +98,10 @@ class AuthorOrCheckerRequiredMixin(object):
# return render(request, "sbas/question_view.html", {"questions": questions})
@login_required
def question_detail(request, pk):
question = get_object_or_404(Question, pk=pk)
return render(request, "sbas/question_detail.html", {"question": question})
#@login_required
#def question_detail(request, pk):
# question = get_object_or_404(Question, pk=pk)
# return render(request, "sbas/question_detail.html", {"question": question})
def active_exams(request):