Ticket #29418: models.py

File models.py, 1.3 KB (added by BeshoyFarag, 6 years ago)

blog models.py

Line 
1from django.db import models
2
3
4from django.urls import reverse
5class Category(models.Model):
6 name = models.CharField (max_length = 160)
7 slug = models.SlugField(max_length = 160,unique=True)
8 date = models.DateTimeField()
9 class meta :
10 ordering = ('name',)
11 verbose_name = 'category'
12 verbose_name_plural = 'categories'
13 def get_absolute_url(self ):
14
15 return "/blog/Category/%s" % self.slug
16 def __str__(self):
17 return self.name
18 def __unicode__(self):
19 return self.name
20
21class Post(models.Model):
22 title = models.CharField (max_length = 160, null=False)
23 body = models.TextField( null=False)
24 date = models.DateTimeField()
25 author = models.CharField (max_length = 160)
26 description = models.TextField(max_length = 160)
27 keywords = models.TextField()
28 category = models.ForeignKey(Category,on_delete=models.DO_NOTHING)
29 slug = models.SlugField(max_length = 160,unique=True)
30 img_url = models.URLField()
31 short_blog_snippet= models.CharField(max_length = 15)
32 absolute_url = models.CharField(max_length=400, blank=True, editable=False)
33
34
35 def __str__(self):
36
37 return self.title
38
39 def get_absolute_url(self ):
40
41 return "/blog/%s" % self.slug
42 def __unicode__(self):
43 return self.title
44
45
46
47
Back to Top