Advertisement
robertvari

Post model with author

Apr 19th, 2020
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. from django.db import models
  2. from django.conf import settings
  3.  
  4.  
  5. class Post(models.Model):
  6.     author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="posts")
  7.  
  8.     title = models.CharField(max_length=200)
  9.     body = models.TextField(max_length=5000)
  10.     created = models.DateTimeField(auto_now_add=True)
  11.     updated = models.DateTimeField(auto_now=True)
  12.  
  13.     def __str__(self):
  14.         return self.title
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement