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

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