diff --git a/docker-compose.yml b/docker-compose.yml index 1abe61e..f39579a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,10 +2,14 @@ version: "2" services: db: build: postgres-hstore + restart: always + volumes: + - /var/spejstore-data:/var/lib/postgresql/data web: build: . - command: wait-for-it db:5432 -- bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000" + restart: always + command: bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000" volumes: - .:/code ports: diff --git a/storage/apiviews.py b/storage/apiviews.py index b2bfed1..4331d24 100644 --- a/storage/apiviews.py +++ b/storage/apiviews.py @@ -6,6 +6,22 @@ from storage.models import Item, Label from storage.serializers import ItemSerializer, LabelSerializer from django.shortcuts import get_object_or_404 +from storage.views import apply_smart_search + + +class SmartSearchFilterBackend(filters.BaseFilterBackend): + """ + Filters query using smartsearch filter + """ + + def filter_queryset(self, request, queryset, view): + search_query = request.query_params.get('smartsearch', None) + if search_query: + return apply_smart_search(search_query, queryset) + + return queryset + + class LabelViewSet(viewsets.ModelViewSet): """ API endpoint that allows items to be viewed or edited. @@ -20,6 +36,9 @@ class ItemViewSet(viewsets.ModelViewSet): """ queryset = Item.objects serializer_class = ItemSerializer + filter_backends = (SmartSearchFilterBackend, filters.OrderingFilter) + ordering_fields = '__all__' + def get_queryset(self): return Item.get_roots() diff --git a/storage/models.py b/storage/models.py index 920d892..a198a28 100644 --- a/storage/models.py +++ b/storage/models.py @@ -28,6 +28,13 @@ class Category(models.Model): return self.name +# TODO label versioning +# Zapisywać w URL na naklejce jej wersję, aby można było łatwo wyłapać +# przedawnione informacje +# Also przechowywać "id" z qrkodów/barkodów w historycznej bazie. +# also qrcody w stylu //s/ID (żeby się resolvowało w sieci lokalnej) +# Also ID zawierające część name + class Item(models.Model, TreeModelMixin): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)