Last active
January 19, 2023 10:28
-
-
Save afrinjamanbd/06cdfb4939bead84f621e783742cb278 to your computer and use it in GitHub Desktop.
django admin model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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