-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SearchFeild PostManager and Varios functionality
- Loading branch information
1 parent
512bdbe
commit 2ce939c
Showing
29 changed files
with
236 additions
and
123 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,7 @@ class Meta: | |
fields = [ | ||
"title", | ||
"content", | ||
"image" | ||
"image", | ||
"draft", | ||
"publish" | ||
] |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2018-06-02 10:35 | ||
from __future__ import unicode_literals | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('posts', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='post', | ||
options={'ordering': ['-timestamp', '-updated']}, | ||
), | ||
migrations.AddField( | ||
model_name='post', | ||
name='user', | ||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2018-06-02 11:03 | ||
from __future__ import unicode_literals | ||
|
||
import datetime | ||
from django.db import migrations, models | ||
from django.utils.timezone import utc | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('posts', '0002_auto_20180602_1605'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='post', | ||
name='draft', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='post', | ||
name='publish', | ||
field=models.DateTimeField(default=datetime.datetime(2018, 6, 2, 11, 3, 15, 124529, tzinfo=utc)), | ||
preserve_default=False, | ||
), | ||
] |
Binary file not shown.
Binary file removed
BIN
-833 Bytes
posts/migrations/__pycache__/0002_auto_20180602_0924.cpython-36.pyc
Binary file not shown.
Binary file added
BIN
+926 Bytes
posts/migrations/__pycache__/0002_auto_20180602_1605.cpython-36.pyc
Binary file not shown.
Binary file added
BIN
+880 Bytes
posts/migrations/__pycache__/0003_auto_20180602_1633.cpython-36.pyc
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,68 @@ | ||
from django.db import models | ||
from django.conf import settings | ||
from django.core.urlresolvers import reverse | ||
from django.db import models | ||
from django.db.models.signals import pre_save | ||
from django.utils import timezone | ||
|
||
#set upload location Accordingly | ||
def upload_location(instance,filename): | ||
print(instance) | ||
return "%s/%s"%(instance.id,filename) | ||
|
||
from django.utils.text import slugify | ||
# Create your models here. | ||
# MVC MODEL VIEW CONTROLLER | ||
class PostManager(models.Manager): | ||
def active(self,*args,**kwargs): | ||
return super(PostManager,self).filter(draft=False).filter(publish__lte=timezone.now()) | ||
|
||
def upload_location(instance, filename): | ||
#filebase, extension = filename.split(".") | ||
#return "%s/%s.%s" %(instance.id, instance.id, extension) | ||
return "%s/%s" %(instance.id, filename) | ||
|
||
class Post(models.Model): | ||
title = models.CharField(max_length=120) | ||
image = models.ImageField(upload_to=upload_location,null=True, | ||
blank=True,width_field="width_field", | ||
height_field="height_field") | ||
width_field = models.IntegerField(default=0) | ||
height_field = models.IntegerField(default=0) | ||
content = models.TextField() | ||
updated = models.DateTimeField(auto_now=True, auto_now_add = False) | ||
timestamp = models.DateTimeField(auto_now=False, auto_now_add = True) | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
def get_absolute_url(self): | ||
return reverse("posts:detail",kwargs={"id":self.id}) | ||
user = models.ForeignKey(settings.AUTH_USER_MODEL,default=1) | ||
title = models.CharField(max_length=120) | ||
slug = models.SlugField(unique=True) | ||
image = models.ImageField(upload_to=upload_location, | ||
null=True, | ||
blank=True, | ||
width_field="width_field", | ||
height_field="height_field") | ||
height_field = models.IntegerField(default=0) | ||
width_field = models.IntegerField(default=0) | ||
content = models.TextField() | ||
draft = models.BooleanField(default=False) | ||
publish = models.DateTimeField(auto_now=False, auto_now_add=False) | ||
updated = models.DateTimeField(auto_now=True, auto_now_add=False) | ||
timestamp = models.DateTimeField(auto_now=False, auto_now_add=True) | ||
objects = PostManager() | ||
def __unicode__(self): | ||
return self.title | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
def get_absolute_url(self): | ||
return reverse("posts:detail", kwargs={"slug": self.slug}) | ||
|
||
class Meta: | ||
ordering = ["-timestamp", "-updated"] | ||
|
||
|
||
|
||
def create_slug(instance, new_slug=None): | ||
slug = slugify(instance.title) | ||
if new_slug is not None: | ||
slug = new_slug | ||
qs = Post.objects.filter(slug=slug).order_by("-id") | ||
exists = qs.exists() | ||
if exists: | ||
new_slug = "%s-%s" %(slug, qs.first().id) | ||
return create_slug(instance, new_slug=new_slug) | ||
return slug | ||
|
||
|
||
def pre_save_post_receiver(sender, instance, *args, **kwargs): | ||
if not instance.slug: | ||
instance.slug = create_slug(instance) | ||
|
||
|
||
|
||
pre_save.connect(pre_save_post_receiver, sender=Post) |
Empty file.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from urllib.parse import quote_plus | ||
from django import template | ||
|
||
register = template.Library() | ||
|
||
@register.filter | ||
def urlify(value): | ||
return quote_plus(value) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,19 @@ | ||
from django.conf.urls import url | ||
from django.contrib import admin | ||
|
||
from .views import ( | ||
post_list, | ||
post_create, | ||
post_detail, | ||
post_update, | ||
post_delete | ||
post_delete, | ||
) | ||
|
||
urlpatterns = [ | ||
url(r'^$', post_list, name='list'), | ||
url(r'^$', post_list, name='list'), | ||
url(r'^create/$', post_create), | ||
url(r'^(?P<id>\d+)/$', post_detail,name='detail'), | ||
url(r'^(?P<id>\d+)/edit/$', post_update,name='update'), | ||
url(r'^(?P<id>\d+)/delete/$', post_delete), | ||
|
||
|
||
] | ||
|
||
|
||
|
||
# urlpatterns = [ | ||
# url(r'^$', "posts.views.post_list"), | ||
# url(r'^create/$', "posts.views.post_create"), | ||
# url(r'^detail/$', "posts.views.post_detail"), | ||
# url(r'^update/$', "posts.views.post_update"), | ||
# url(r'^delete/$', "posts.views.post_delete"), | ||
|
||
|
||
# ] | ||
url(r'^(?P<slug>[\w-]+)/$', post_detail, name='detail'), | ||
url(r'^(?P<slug>[\w-]+)/edit/$', post_update, name='update'), | ||
url(r'^(?P<slug>[\w-]+)/delete/$', post_delete), | ||
#url(r'^posts/$', "<appname>.views.<function_name>"), | ||
] |
Oops, something went wrong.