1
0
Fork 0
mirror of https://github.com/Findus23/acronomy.git synced 2024-09-19 15:33:45 +02:00
acronomy/acros/models/Acronym.py

33 lines
1,014 B
Python
Raw Normal View History

2020-06-01 11:03:21 +02:00
from django.db import models
from django.urls import reverse
from django.utils.text import slugify
from simple_history.models import HistoricalRecords
from acros.models import Tag
2020-06-01 20:26:00 +02:00
from acros.utils.conversion import md_to_html
2020-06-01 11:03:21 +02:00
class Acronym(models.Model):
name = models.CharField(max_length=100)
full_name = models.CharField(max_length=1000)
slug = models.SlugField(null=False, unique=True)
description_md = models.TextField(blank=True)
description_html = models.TextField(editable=False)
history = HistoricalRecords()
tags = models.ManyToManyField(Tag, related_name="acronyms")
def save(self, *args, **kwargs):
self.description_html = md_to_html(self.description_md)
if not self.slug:
self.slug = slugify(self.name)
super(Acronym, self).save(*args, **kwargs)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('detail', args=[str(self.slug)])
class Meta:
ordering = ["name"]