.
class Past_Question(models.Model):
author = models.ForeignKey(User,on_delete=models.CASCADE)
read_min = models.CharField(max_length=30,default='30 mins estimated study time')
tag = models.CharField(max_length=300,default='Past_Question')
title = models.TextField(null=True,blank=False)
topic = models.TextField(null=True,blank=True)
keyword = models.TextField(blank=True,null=True)
table_of_content = RichTextUploadingField(blank=False)
content = RichTextUploadingField(blank=False)
learning_objective = RichTextUploadingField(blank=True)
image = models.ImageField(blank=True, null=True)
date_added = models.DateTimeField(default=datetime.now,blank=True)
slug = models.SlugField(max_length=250,blank=True,unique=True)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse ("past_detail",kwargs={'slug':self.slug})
def save(self, *args, **kwargs): # new
if not self.slug:
self.slug = slugify(self.title)
return super().save(*args, **kwargs)