from __future__ import unicode_literals

from django.db import models

# Create your models here.

from __future__ import unicode_literals

from django.db import models
from django.utils import timezone

# Create your models here.

class Post(models.Model):
    author = models.ForeignKey('auth.User')
    title = models.CharField(max_length=200)
    text = models.TextField()
    created_date = models.DateTimeField(default=timezone.now)
    published_date = models.DateTimeField(blank=True, null=True)

    def publish(self):
        self.published_date = timezone.now()
        self.save()

    def __str__(self):
        return self.title
Create Post model in model.py
Create Post model in model.py

  from __future__ import unicode_literals
  
  from django.db import models
+ from django.utils import timezone
  
  # Create your models here.
  
+ class Post(models.Model):
+     author = models.ForeignKey('auth.User')
+     title = models.CharField(max_length=200)
+     text = models.TextField()
+     created_date = models.DateTimeField(default=timezone.now)
+     published_date = models.DateTimeField(blank=True, null=True)
+ 
+     def publish(self):
+         self.published_date = timezone.now()
+         self.save()
+ 
+     def __str__(self):
+         return self.title
Create Post model in model.py
## Code Before:
from __future__ import unicode_literals

from django.db import models

# Create your models here.

## Instruction:
Create Post model in model.py
## Code After:
from __future__ import unicode_literals

from django.db import models
from django.utils import timezone

# Create your models here.

class Post(models.Model):
    author = models.ForeignKey('auth.User')
    title = models.CharField(max_length=200)
    text = models.TextField()
    created_date = models.DateTimeField(default=timezone.now)
    published_date = models.DateTimeField(blank=True, null=True)

    def publish(self):
        self.published_date = timezone.now()
        self.save()

    def __str__(self):
        return self.title