LIL-116. Реализовать выпадающий список категорий курсов в главном шаблоне

remotes/origin/hasaccess
Ivlev Denis 8 years ago
parent 94956bbf21
commit 9a380454a4
  1. 11
      apps/course/filters.py
  2. 2
      apps/course/templates/course/inclusion/category_menu_items.html
  3. 6
      apps/course/views.py
  4. 18
      docker-compose.yml
  5. 17
      project/settings.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']

@ -1,5 +1,5 @@
{% for category in category_items %}
<a class="header__link" href="#">
<a class="header__link" href="{% url 'courses' %}?category={{ category.title }}">
<div class="header__title">{{ category.title }}</div>
</a>
{% endfor %}

@ -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'

@ -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
- db
links:
- db

@ -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

Loading…
Cancel
Save