added guide type filter to guide list view

This commit is contained in:
Anatoly 2020-02-05 14:16:36 +03:00
parent 34adf748ed
commit 6d9852fc7b
4 changed files with 51 additions and 6 deletions

View File

@ -41,12 +41,18 @@ class GuideFilterSet(filters.FilterSet):
'Use for Establishment detail\'s sheet to content display within '
'"Collections & Guides" tab.'
)
guide_type = filters.ChoiceFilter(
choices=models.Guide.GUIDE_TYPE_CHOICES,
help_text=f'It allows filtering guide list by type.'
f'Enum: {dict(models.Guide.GUIDE_TYPE_CHOICES)}'
)
class Meta:
"""Meta class."""
model = models.Guide
fields = (
'establishment_id',
'guide_type',
)
def by_establishment_id(self, queryset, name, value):

View File

@ -137,8 +137,8 @@ class GuideBaseSerializer(serializers.ModelSerializer):
'count_objects_during_init',
]
extra_kwargs = {
'guide_type': {'write_only': True},
'site': {'write_only': True},
'guide_type': {'write_only': True, 'required': True},
'site': {'write_only': True, 'required': True},
'state': {'write_only': True},
'start': {'required': True},
'slug': {'required': False},

View File

@ -100,9 +100,48 @@ class CollectionBackOfficeList(CollectionBackOfficeViewSet):
pagination_class = None
class GuideListCreateView(GuideBaseView,
generics.ListCreateAPIView):
"""View for Guides list for BackOffice users and Guide create."""
class GuideListCreateView(GuideBaseView, generics.ListCreateAPIView):
"""
## Guide list/create view.
### Request
For creating new instance of Guide model, need to pass the following data in the request:
required fields:
* name (str) - guide name
* start (str) - guide start date (datetime in a format `ISO-8601`)
* vintage (str) - valid year
* guide_type (int) - guide type enum: `0 (Restaurant), 1 (Artisan), 2 (Wine)`
* site (int) - identifier of site
non-required fields:
* slug - generated automatically if not provided
* state - state enum`: `0 (Built), 1 (Waiting), 2 (Removing), 3 (Building)` (service states)
* end - guide end date (datetime in a format `ISO-8601`)
### Response
Return paginated list of guides.
I.e.:
```
{
"count": 58,
"next": 2,
"previous": null,
"results": [
{
"id": 1,
...
}
]
}
```
### Description
*GET*
Return paginated list of guides with the opportunity of filtering by next fields:
* establishment_id (int) - identifier of establishment,
* guide_type (int) - guide type enum: `0 (Restaurant), 1 (Artisan), 2 (Wine)`
*POST*
Create a new instance of guide.
"""
filter_class = filters.GuideFilterSet
def create(self, request, *args, **kwargs):

File diff suppressed because one or more lines are too long