Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

models.py 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. from django.db import models
  2. from django.contrib.auth.models import User
  3. from django.utils import timezone
  4. from taggit.managers import TaggableManager
  5. from datetime import datetime
  6. #external code customised
  7. #import from https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model
  8. class CustomUser(models.Model):
  9. user = models.OneToOneField(User, null=True, on_delete=models.CASCADE)
  10. #add tags to User Model with possibility to leave empty
  11. tags = TaggableManager(blank=True)
  12. #external code customised
  13. #import from https://tutorial.djangogirls.org/en/django_models/
  14. class Post(models.Model):
  15. author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
  16. title = models.CharField(max_length=200)
  17. text = models.TextField()
  18. created_date = models.DateTimeField(default=timezone.now)
  19. published_date = models.DateTimeField(blank=True, null=True)
  20. #add tags to Post Model
  21. tags = TaggableManager()
  22. def publish(self):
  23. self.published_date = timezone.now()
  24. self.save()
  25. def __str__(self):
  26. return self.title