From 8d65d58998229d921a38967f812a25c39d5ba182 Mon Sep 17 00:00:00 2001 From: Nishant Pandey Date: Thu, 4 Jul 2019 00:29:24 +0530 Subject: [PATCH] docs: Model updated --- questions/admin.py | 9 +++++++- questions/models.py | 51 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/questions/admin.py b/questions/admin.py index 6723db8..cb98c31 100644 --- a/questions/admin.py +++ b/questions/admin.py @@ -1,5 +1,12 @@ from django.contrib import admin from .models import * +admin.site.register(Question) +admin.site.register(min_mark) +admin.site.register(max_mark) +admin.site.register(difficulty) admin.site.register(Topic) -admin.site.register(Type) \ No newline at end of file +admin.site.register(Type) +admin.site.register(date) +admin.site.register(author) + diff --git a/questions/models.py b/questions/models.py index 4abb484..2475ed4 100644 --- a/questions/models.py +++ b/questions/models.py @@ -1,21 +1,60 @@ from django.db import models +from ckeditor.fields import RichTextField +from django.core.validators import MinValueValidator +from django.template.defaultfilters import truncatechars +from enum import Enum +from django.contrib.auth.models import User + +class stat(Enum): + ve= 'Very easy' + e= 'Easy' + mod= 'Moderate' + hard= 'Hard' + Exp= 'Expert' + +class Question(models.Model): + name= RichTextField() + @property + def short_description(self): + return truncatechars(self.description, 100) + + +class min_mark(models.Model): + marks= models.IntegerField(validators=[MinValueValidator(10)]) + +class max_mark(models.Model): + marks= models.IntegerField() + +class difficulty(models.Model): + level= models.CharField(max_length= 10, choices=[(tag, tag.value) for tag in stat]) + class Topic(models.Model): name = models.CharField(max_length=50) - parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True) + parent = models.ManyToManyField(Question) + + def __str__(self): + return self.name -def __str__(self): - return self.name class Type(models.Model): name = models.CharField(max_length=50) - + parent= models.ForeignKey(Question, related_name='type', null=True, blank=True, on_delete= models.CASCADE) class Meta: verbose_name = "Type" verbose_name_plural = "Types" - + def __str__(self): - return self.name \ No newline at end of file + return self.name + + + +class date(models.Model): + date= models.DateField(auto_now_add=True) + +class author(models.Model): + designed_by= models.ForeignKey(User, related_name='+', on_delete= models.CASCADE) +