from django.db import models from django.contrib.auth.models import User from django.utils import timezone from taggit.managers import TaggableManager from datetime import datetime #external code customised #import from https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model class CustomUser(models.Model): user = models.OneToOneField(User, null=True, on_delete=models.CASCADE) #add tags to User Model with possibility to leave empty tags = TaggableManager(blank=True) #external code customised #import from https://tutorial.djangogirls.org/en/django_models/ class Post(models.Model): author = models.ForeignKey('auth.User', on_delete=models.CASCADE) title = models.CharField(max_length=200) text = models.TextField() created_date = models.DateTimeField(default=timezone.now) published_date = models.DateTimeField(blank=True, null=True) #add tags to Post Model tags = TaggableManager() def publish(self): self.published_date = timezone.now() self.save() def __str__(self): return self.title