Skip to content

Commit

Permalink
Fix-amfoss#5
Browse files Browse the repository at this point in the history
  • Loading branch information
amreshk005 committed Sep 7, 2019
1 parent e25422d commit 4a38d1f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
15 changes: 11 additions & 4 deletions questions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
44 changes: 41 additions & 3 deletions questions/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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)
2 changes: 1 addition & 1 deletion qujini/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down
2 changes: 1 addition & 1 deletion qujini/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
urlpatterns = [
path('admin/', admin.site.urls),
]
admin.site.site_title="Qujini"
admin.site.site_title = "Qujini"

0 comments on commit 4a38d1f

Please sign in to comment.