Skip to content

Commit

Permalink
Fix-amfoss#5
Browse files Browse the repository at this point in the history
Alignment Fixed

Alignment Fixed

Alignment Fixed

Question Model Added
  • Loading branch information
amreshk005 committed Sep 12, 2019
1 parent e25422d commit b6826df
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
19 changes: 15 additions & 4 deletions questions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
from .models import *


class SnippetAdmin(admin.ModelAdmin):
change_list_template = 'admin/questions/login.html'
class OrderAdmin(admin.ModelAdmin):
fields = ('author', ('min_mark', 'max_mark', 'difficulty', 'date'),
'question_type', 'question', 'topic')

fields = ('author', ('min_mark', 'max_mark', 'difficulty', 'date'),
'topic', 'questionType', 'question',)

admin.site.register(Topic, SnippetAdmin)
admin.site.register(Type, SnippetAdmin)
list_display = ('question_trim', 'mark_range',
'difficulty', 'questionType', 'get_topics', 'author')

search_fields = ('question_trim', 'difficulty',
'questionType', 'get_topics' 'author')


admin.site.register(Topic)
admin.site.register(Type)
admin.site.register(Question, OrderAdmin)
43 changes: 40 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,37 @@ 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'),
]
author = models.ForeignKey(User, on_delete=models.CASCADE)
min_mark = models.IntegerField()
max_mark = models.IntegerField(null=True)
difficulty = models.CharField(
max_length=20,
choices=difficulty_choices,
default=VeryEasy
)
date = models.DateField()
questionType = models.ForeignKey(Type, on_delete=models.CASCADE)
question = RichTextField(blank=True, null=True)
topic = models.ManyToManyField(Topic)

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 b6826df

Please sign in to comment.