Skip to content

Instantly share code, notes, and snippets.

@afrinjamanbd
Last active January 19, 2023 10:28
Show Gist options
  • Save afrinjamanbd/06cdfb4939bead84f621e783742cb278 to your computer and use it in GitHub Desktop.
Save afrinjamanbd/06cdfb4939bead84f621e783742cb278 to your computer and use it in GitHub Desktop.
django admin model
from django.contrib.auth.models import User
from django.db import models
from django.utils import timezone
class Catagory(models.Model):
title = models.CharField(max_length=100)
def __str__(self):
return self.title
class MyPost(models.Model):
options = (('draft', 'Draft'),('published','Published'),)
title = models.CharField(max_length=100)
catagory = models.ForeignKey(Catagory,on_delete=models.PROTECT,default=1)
detail = models.TextField(null=True)
slug = models.SlugField(max_length=200,unique_for_date='publish',null=True)
author = models.ForeignKey(User, on_delete=models.CASCADE,related_name='app_mypost',null=True)
publish = models.DateField(default=timezone.now)
content = models.TextField(null=True)
status = models.CharField(max_length=10,choices=options, default='draft')
class Meta :
verbose_name = ('Post')
verbose_name_plural = ('Posts')
def __str__(self):
return self.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment