pages.models.Article.__str__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 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