Skip to content

Commit a4ace2f

Browse files
author
Guillermo Alvarez
committed
#comment anadidos los modelos basicos para el blog, incluido el modelo para las imagenes
1 parent ae4fb89 commit a4ace2f

File tree

26 files changed

+96
-1
lines changed

26 files changed

+96
-1
lines changed

blog-api/apps/api/__init__.py

Whitespace-only changes.

blog-api/apps/api/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

blog-api/apps/api/migrations/__init__.py

Whitespace-only changes.

blog-api/apps/api/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

blog-api/apps/api/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

blog-api/apps/api/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

blog-api/apps/blog/__init__.py

Whitespace-only changes.

blog-api/apps/blog/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

blog-api/apps/blog/migrations/__init__.py

Whitespace-only changes.

blog-api/apps/blog/models.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
from django.db import models
3+
from django.conf import settings
4+
from django.utils.text import slugify
5+
from django.utils.encoding import python_2_unicode_compatible
6+
7+
from core.models import TimeStampedModel
8+
9+
10+
@python_2_unicode_compatible
11+
class Post(TimeStampedModel, models.Model):
12+
title = models.CharField(max_length=255)
13+
slug = models.SlugField(max_length=255)
14+
body = models.TextField(blank=True, null=True)
15+
author = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='posts')
16+
17+
def __str__(self):
18+
return self.title
19+
20+
def save(self, *args, **kwargs):
21+
self.slug = slugify(self.title)
22+
super(Post, self).save(*args, **kwargs)

blog-api/apps/blog/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

blog-api/apps/blog/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

blog-api/apps/core/__init__.py

Whitespace-only changes.

blog-api/apps/core/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

blog-api/apps/core/migrations/__init__.py

Whitespace-only changes.

blog-api/apps/core/models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
from django.db import models
3+
4+
5+
class TimeStampedModel(models.Model):
6+
"""
7+
A abstract model that provides self-updating (created) and modified fields.
8+
9+
"""
10+
created = models.DateTimeField(auto_now_add=True)
11+
modified = models.DateTimeField(auto_now=True)
12+
13+
class Meta:
14+
abstract = True

blog-api/apps/core/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

blog-api/apps/core/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

blog-api/apps/images/__init__.py

Whitespace-only changes.

blog-api/apps/images/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

blog-api/apps/images/migrations/__init__.py

Whitespace-only changes.

blog-api/apps/images/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
from django.db import models
3+
4+
from blog.models import Post
5+
from core.models import TimeStampedModel
6+
7+
8+
class Photo(TimeStampedModel, models.Model):
9+
image = models.ImageField(upload_to="%Y/%m/%d")
10+
post = models.ForeignKey(Post, related_name='photos')
11+

blog-api/apps/images/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

blog-api/apps/images/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

blog-api/config/common.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111

1212
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1313
import os
14+
from sys import path
1415
from os.path import join, dirname
1516

1617
from configurations import Configuration, values
1718

1819
BASE_DIR = dirname(dirname(__file__))
1920

21+
APPS_DIR = join(BASE_DIR, 'apps')
22+
path.insert(1, APPS_DIR)
23+
2024

2125
class Common(Configuration):
2226

@@ -260,6 +264,11 @@ class Common(Configuration):
260264
'level': 'ERROR',
261265
'propagate': True,
262266
},
267+
'blog': {
268+
'handlers': ['console'],
269+
'level': 'DEBUG',
270+
'propagate': True,
271+
},
263272
}
264273
}
265274
# END LOGGING CONFIGURATION

blog-api/users/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from django.utils.translation import ugettext_lazy as _
99

1010

11-
# Subclass AbstractUser
1211
class User(AbstractUser):
12+
followers = models.ManyToManyField('self', related_name='followers', symmetrical=False)
1313

1414
def __unicode__(self):
1515
return self.username

0 commit comments

Comments
 (0)