-
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.
Merge branch 'Feature/#18' of https://github.com/wafflestudio18-5/tea…
…m2-server into Feature/#18
- Loading branch information
Showing
13 changed files
with
450 additions
and
37 deletions.
There are no files selected for viewing
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
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,3 +1,53 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from .models import Story | ||
|
||
|
||
class TrendingListFilter(admin.SimpleListFilter): | ||
title = 'Trending' | ||
|
||
parameter_name = 'trending' | ||
|
||
def lookups(self, request, model_admin): | ||
return ( | ||
('true', 'is trending'), | ||
('false', 'is not trending'), | ||
) | ||
|
||
def queryset(self, request, queryset): | ||
if self.value() == 'true': | ||
return queryset.filter(trending_order__gte=1, | ||
trending_order__lte=6).order_by('trending_order') | ||
if self.value() == 'false': | ||
return queryset.filter(trending_order=None) | ||
|
||
|
||
class MainListFilter(admin.SimpleListFilter): | ||
title = 'Main' | ||
|
||
parameter_name = 'main' | ||
|
||
def lookups(self, request, model_admin): | ||
return ( | ||
('true', 'is main'), | ||
('false', 'is not main'), | ||
) | ||
|
||
def queryset(self, request, queryset): | ||
if self.value() == 'true': | ||
return queryset.filter(main_order__gte=1, | ||
main_order__lte=6).order_by('trending_order') | ||
if self.value() == 'false': | ||
return queryset.filter(main_order=None) | ||
|
||
|
||
class StoryAdmin(admin.ModelAdmin): | ||
list_display = ('id', 'writer_id', 'writer', 'title', 'main_order', 'trending_order', 'published_at') | ||
list_display_links = ('title',) | ||
list_editable = ('main_order', 'trending_order') | ||
list_filter = (MainListFilter, TrendingListFilter) | ||
ordering = ('-published_at',) | ||
search_fields = ['writer__username', 'writer__userprofile__name'] | ||
|
||
|
||
admin.site.register(Story, StoryAdmin) |
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,23 @@ | ||
# Generated by Django 3.1.3 on 2021-01-02 17:53 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('story', '0005_auto_20210101_1728'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='story', | ||
name='main_order', | ||
field=models.PositiveSmallIntegerField(blank=True, choices=[(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5')], null=True), | ||
), | ||
migrations.AddField( | ||
model_name='story', | ||
name='trending_order', | ||
field=models.PositiveSmallIntegerField(blank=True, choices=[(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5'), (6, '6')], null=True), | ||
), | ||
] |
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 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,17 @@ | ||
from rest_framework.pagination import PageNumberPagination | ||
from rest_framework.response import Response | ||
|
||
|
||
class StoryPagination(PageNumberPagination): | ||
page_size = 10 | ||
|
||
def get_paginated_response(self, data): | ||
return Response(self.get_paginated_data(data)) | ||
|
||
def get_paginated_data(self, data): | ||
return { | ||
'count': self.page.paginator.count, | ||
'next': self.get_next_link(), | ||
'previous': self.get_previous_link(), | ||
'stories': data | ||
} |
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 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
Oops, something went wrong.