From 4a38d1fa5cf68b975fb299134b35d921b75142ce Mon Sep 17 00:00:00 2001 From: amreshk005 Date: Sat, 7 Sep 2019 21:24:31 +0530 Subject: [PATCH] Fix-#5 --- questions/admin.py | 15 +++++++++++---- questions/models.py | 44 +++++++++++++++++++++++++++++++++++++++++--- qujini/settings.py | 2 +- qujini/urls.py | 2 +- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/questions/admin.py b/questions/admin.py index 4b92045..5e865b6 100644 --- a/questions/admin.py +++ b/questions/admin.py @@ -2,9 +2,16 @@ from .models import * -class SnippetAdmin(admin.ModelAdmin): - change_list_template = 'admin/questions/login.html' +class OrderAdmin(admin.ModelAdmin): -admin.site.register(Topic, SnippetAdmin) -admin.site.register(Type, SnippetAdmin) + list_display = ('question_trim', 'mark_range', + 'difficulty', 'type', 'get_topics', 'author') + + search_fields = ('question_trim', 'difficulty', + 'type', 'get_topics' 'author') + + +admin.site.register(Topic) +admin.site.register(Type) +admin.site.register(Question, OrderAdmin) diff --git a/questions/models.py b/questions/models.py index b40f349..83e282d 100644 --- a/questions/models.py +++ b/questions/models.py @@ -1,13 +1,16 @@ from django.db import models +from django.contrib.auth.models import User +from django.template.defaultfilters import truncatechars +from ckeditor.fields import RichTextField class Topic(models.Model): name = models.CharField(max_length=50) - parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True) - + parent = models.ForeignKey( + 'self', on_delete=models.CASCADE, null=True, blank=True) def __str__(self): - return self.name + return self.name class Type(models.Model): @@ -20,3 +23,38 @@ class Meta: def __str__(self): return self.name + +class Question(models.Model): + VeryEasy = 'Very Easy' + Easy = 'Easy' + Moderate = 'Moderate' + Expert = 'Expert' + difficulty_choices = [ + (VeryEasy, 'VeryEasy'), + (Easy, 'Easy'), + (Moderate, 'Moderate'), + (Expert, 'Expert'), + ] + + question = RichTextField(blank=True, null=True) + min_mark = models.IntegerField() + max_mark = models.IntegerField(null=True) + difficulty = models.CharField( + max_length=20, + choices=difficulty_choices, + default=VeryEasy, + ) + type = models.ForeignKey(Type, on_delete=models.CASCADE) + topic = models.ManyToManyField(Topic) + date = models.DateField() + author = models.ForeignKey(User, on_delete=models.CASCADE) + + def mark_range(self): + return '{}-{}'.format(self.min_mark, self.max_mark) + + def get_topics(self): + return "\n".join([p.name for p in self.topic.all()]) + + @property + def question_trim(self): + return truncatechars(self.question, 100) diff --git a/qujini/settings.py b/qujini/settings.py index 63504fd..3965d8c 100644 --- a/qujini/settings.py +++ b/qujini/settings.py @@ -56,7 +56,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [os.path.join(BASE_DIR, 'templates'),os.path.join(BASE_DIR, 'static')], + 'DIRS': [os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'static')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/qujini/urls.py b/qujini/urls.py index 066f22f..306802d 100644 --- a/qujini/urls.py +++ b/qujini/urls.py @@ -19,5 +19,5 @@ urlpatterns = [ path('admin/', admin.site.urls), ] -admin.site.site_title="Qujini" +admin.site.site_title = "Qujini"