pages.models   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Article.__str__() 0 3 1
A Article.publish() 0 4 1
1
""" Models are objects used in the website. """
2
from django.db import models
3
from django.utils import timezone
4
from tinymce.models import HTMLField
5
6
7
class Article(models.Model):
8
    """" This model is an article. """
9
    author = models.ForeignKey('auth.User', on_delete=models.PROTECT)
10
    title = models.CharField(max_length=200)
11
    # An HTMLField will use the TinyMCE editor, a TextField won't
12
    text = HTMLField()
13
    created_date = models.DateTimeField(default=timezone.now)
14
    published_date = models.DateTimeField(blank=True, null=True)
15
16
    def publish(self) -> None:
17
        """" Publish article now. """
18
        self.published_date = timezone.now()
19
        self.save()
20
21
    def __str__(self) -> str:
22
        """ Python to-string method. """
23
        return self.title
24