Skip to content

Commit 01cb4dd

Browse files
committed
added filter
1 parent 2dcd58b commit 01cb4dd

23 files changed

Lines changed: 83 additions & 184 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ ipython_config.py
109109

110110
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
111111
__pypackages__/
112-
112+
example.json
113113
# Celery stuff
114114
celerybeat-schedule
115115
celerybeat.pid

Pipfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ name = "pypi"
66
[packages]
77
Pillow = "*"
88
django-crispy-forms = "*"
9-
djangorestframework-filters = "*"
10-
django-filter = "==21.1"
119

1210
[dev-packages]
1311

curations/migrations/0001_initial.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 3.2.6 on 2021-09-13 05:01
1+
# Generated by Django 4.0.2 on 2022-02-20 14:31
22

33
from django.conf import settings
44
from django.db import migrations, models
@@ -21,7 +21,8 @@ class Migration(migrations.Migration):
2121
('title', models.CharField(max_length=64)),
2222
('description', models.TextField()),
2323
('upvotes', models.IntegerField(default=0)),
24-
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
24+
('created_at', models.DateTimeField(auto_now_add=True)),
25+
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='curations', to=settings.AUTH_USER_MODEL)),
2526
],
2627
),
2728
migrations.CreateModel(
@@ -72,6 +73,6 @@ class Migration(migrations.Migration):
7273
migrations.AddField(
7374
model_name='curation',
7475
name='subject',
75-
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='curations.subject'),
76+
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='curations', to='curations.subject'),
7677
),
7778
]

curations/migrations/0002_alter_curation_owner.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

curations/migrations/0002_alter_curation_subject.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

curations/migrations/0003_merge_20220219_1825.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

curations/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from datetime import date
2+
from sqlite3 import Date
3+
from statistics import mode
14
from django.db import models
25
from django.contrib.auth import get_user, get_user_model
36

4-
57
# Create your models here.
68
class Curation(models.Model):
79
title = models.CharField(max_length=64)
@@ -13,6 +15,7 @@ class Curation(models.Model):
1315
subject = models.ForeignKey(
1416
"Subject", related_name="curations", on_delete=models.CASCADE
1517
)
18+
created_at = models.DateTimeField(auto_now_add=True, blank=True)
1619

1720
def __str__(self):
1821
return self.title

curatorbackendapi/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"crispy_forms",
4242
"curations",
4343
"userProfiles",
44-
"django_filters",
4544
]
4645

4746
MIDDLEWARE = [
@@ -138,7 +137,7 @@
138137
STATIC_URL = "/static/"
139138
STATICFILES_DIRS = [
140139
os.path.join(BASE_DIR, "static"),
141-
"/var/www/static/",
140+
# "/var/www/static/",
142141
]
143142
# STATIC_ROOT = os.path.join(BASE_DIR, "static")
144143

curatorbackendapi/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from asyncio import constants
12
from django.views.generic import View, ListView
23
from django.contrib.auth import login
34
from django.shortcuts import redirect, render
@@ -46,6 +47,7 @@ def get(self, request, *args, **kwargs):
4647
title = kwargs["sub"]
4748
subject = Subject.objects.filter(title=title)[0]
4849
curation_count = subject.curations.all().count()
50+
4951
# filtering Data
5052
search_term = request.GET.get("search")
5153
if search_term:
@@ -57,6 +59,9 @@ def get(self, request, *args, **kwargs):
5759
curations_whole = Curation.objects.filter(subject=subject).order_by(
5860
"-upvotes"
5961
)
62+
filter_term = request.GET.get("filter")
63+
if filter_term:
64+
curations_whole = curations_whole.order_by(filter_term)
6065

6166
# pagination stuff
6267
p = Paginator(curations_whole, 15)

mydatabase

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)