diff --git a/apps/course/filters.py b/apps/course/filters.py new file mode 100644 index 00000000..a86677be --- /dev/null +++ b/apps/course/filters.py @@ -0,0 +1,11 @@ +import django_filters + +from .models import Course + + +class CourseFilter(django_filters.FilterSet): + category__title = django_filters.CharFilter(lookup_expr='iexact') + + class Meta: + model = Course + fields = ['category'] diff --git a/apps/course/templates/course/inclusion/category_menu_items.html b/apps/course/templates/course/inclusion/category_menu_items.html index a6b5528a..80a82615 100644 --- a/apps/course/templates/course/inclusion/category_menu_items.html +++ b/apps/course/templates/course/inclusion/category_menu_items.html @@ -1,5 +1,5 @@ {% for category in category_items %} - +
{{ category.title }}
{% endfor %} \ No newline at end of file diff --git a/apps/course/views.py b/apps/course/views.py index 03beac76..bc3761f1 100644 --- a/apps/course/views.py +++ b/apps/course/views.py @@ -1,6 +1,7 @@ from django.views.generic import ListView from .models import Course +from .filters import CourseFilter class CoursesView(ListView): @@ -8,6 +9,11 @@ class CoursesView(ListView): context_object_name = "course_items" paginate_by = 6 + def get_queryset(self): + queryset = super().get_queryset() + filtered = CourseFilter(self.request.GET, queryset=queryset) + return filtered.qs + def get_template_names(self): if self.request.is_ajax(): return 'course/course_items.html' diff --git a/docker-compose.yml b/docker-compose.yml index 69420d7b..57469a32 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,15 @@ version: '3' + services: - postgres: - image: postgres:9.6 + db: + image: postgres:9.6.3 environment: - - POSTGRES_PASSWORD=1234 - - POSTGRES_USER=postgres + - POSTGRES_DB=lilcity + - POSTGRES_USER=lilcity + - POSTGRES_PASSWORD=GPVs/E/{5&qe + - PGDATA=/var/lib/postgresql/data/pgdata + ports: + - "5432:5432" web: build: . @@ -14,7 +19,10 @@ services: command: bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000" environment: - DJANGO_SETTINGS_MODULE=project.settings + - DATABASE_SERVICE_HOST=db ports: - "8000:8000" depends_on: - - postgres \ No newline at end of file + - db + links: + - db \ No newline at end of file diff --git a/project/settings.py b/project/settings.py index 10946d9e..e2374617 100644 --- a/project/settings.py +++ b/project/settings.py @@ -40,6 +40,7 @@ INSTALLED_APPS = [ ] + [ 'anymail', 'active_link', + 'django_filters', ] + [ 'apps.auth.apps', 'apps.user', @@ -84,14 +85,24 @@ WSGI_APPLICATION = 'project.wsgi.application' # Database # https://docs.djangoproject.com/en/2.0/ref/settings/#databases +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), +# } +# } + DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'lilcity', + 'USER': 'lilcity', + 'PASSWORD': 'GPVs/E/{5&qe', + 'HOST': os.getenv('DATABASE_SERVICE_HOST', '127.0.0.1'), + 'PORT': 5432, } } - # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators