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 791B

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
12345678910111213141516171819202122232425262728
  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. class CustomUser(models.Model):
  6. user = models.OneToOneField(
  7. 'auth.User', null=True, on_delete=models.CASCADE)
  8. tags = TaggableManager()
  9. class Post(models.Model):
  10. author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
  11. title = models.CharField(max_length=200)
  12. text = models.TextField()
  13. created_date = models.DateTimeField(
  14. default=timezone.now)
  15. published_date = models.DateTimeField(
  16. blank=True, null=True)
  17. tags = TaggableManager()
  18. def publish(self):
  19. self.published_date = timezone.now()
  20. self.save()
  21. def __str__(self):
  22. return self.title