-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
38 lines (30 loc) · 1.39 KB
/
models.py
File metadata and controls
38 lines (30 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
class Post(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
pub_date = models.DateTimeField(default=timezone.now)
def __str__(self):
return self.title
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)
image = models.ImageField(upload_to="profile_pics", blank=True, null=True)
bio = models.TextField(blank=True, null=True)
facebook = models.CharField(max_length=300, blank=True, null=True)
instagram = models.CharField(max_length=300, blank=True, null=True)
linkedin = models.CharField(max_length=300, blank=True, null=True)
def __str__(self):
return str(self.user)
class BlogPost(models.Model):
title=models.CharField(max_length=255)
author= models.ForeignKey(User, on_delete=models.CASCADE)
slug=models.CharField(max_length=130)
content=models.TextField()
image = models.ImageField(upload_to="profile_pics", blank=True, null=True)
dateTime=models.DateTimeField(auto_now_add=True)
def __str__(self):
return str(self.author) + " Blog Title: " + self.title
def get_absolute_url(self):
return reverse('blogs')