Commit 44c82752cc58232b572efcc51112a30028703c50
1 parent
b737ff62
Exists in
master
and in
3 other branches
checking if resources are available when deleting subject is done
Showing
1 changed file
with
5 additions
and
2 deletions
Show diff stats
subjects/views.py
... | ... | @@ -426,10 +426,13 @@ class SubjectDeleteView(LoginRequiredMixin, LogMixin, DeleteView): |
426 | 426 | |
427 | 427 | def get(self, request, *args, **kwargs): |
428 | 428 | self.object = self.get_object() |
429 | - if self.object.students.all().count() > 0: | |
429 | + if self.object.students.count() > 0: | |
430 | 430 | messages.error(self.request, _("Subject can't be removed. The subject still possess students and learning objects associated")) |
431 | - | |
432 | 431 | return JsonResponse({'error':True,'url':reverse_lazy('subjects:index')}) |
432 | + for topic in self.object.topic_subject.all(): | |
433 | + if topic.resource_topic.count() > 0: | |
434 | + messages.error(self.request, _("Subject can't be removed. The subject still possess students and learning objects associated")) | |
435 | + return JsonResponse({'error':True,'url':reverse_lazy('subjects:index')}) | |
433 | 436 | context = self.get_context_data(object=self.object) |
434 | 437 | return self.render_to_response(context) |
435 | 438 | ... | ... |