demo-HTML-over-WebSockets-i.../apps/back/models.py

33 lines
798 B
Python
Raw Normal View History

2021-03-07 18:15:29 +01:00
from django.db import models
2021-03-09 22:03:17 +01:00
STATUS = (
(0,"Draft"),
(1,"Publish")
)
class Post(models.Model):
title = models.CharField(max_length=200, unique=True)
author = models.CharField(max_length=20)
content = models.TextField()
status = models.IntegerField(choices=STATUS, default=0)
created_on = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['-created_on']
def __str__(self):
return self.title
class Comment(models.Model):
name = models.CharField(max_length=20)
body = models.CharField(max_length=128)
post = models.ForeignKey(Post, on_delete= models.CASCADE)
created_on = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['-created_on']
def __str__(self):
return self.name