added guide type filter to guide list view
This commit is contained in:
parent
34adf748ed
commit
6d9852fc7b
|
|
@ -41,12 +41,18 @@ class GuideFilterSet(filters.FilterSet):
|
||||||
'Use for Establishment detail\'s sheet to content display within '
|
'Use for Establishment detail\'s sheet to content display within '
|
||||||
'"Collections & Guides" tab.'
|
'"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:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
model = models.Guide
|
model = models.Guide
|
||||||
fields = (
|
fields = (
|
||||||
'establishment_id',
|
'establishment_id',
|
||||||
|
'guide_type',
|
||||||
)
|
)
|
||||||
|
|
||||||
def by_establishment_id(self, queryset, name, value):
|
def by_establishment_id(self, queryset, name, value):
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,8 @@ class GuideBaseSerializer(serializers.ModelSerializer):
|
||||||
'count_objects_during_init',
|
'count_objects_during_init',
|
||||||
]
|
]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
'guide_type': {'write_only': True},
|
'guide_type': {'write_only': True, 'required': True},
|
||||||
'site': {'write_only': True},
|
'site': {'write_only': True, 'required': True},
|
||||||
'state': {'write_only': True},
|
'state': {'write_only': True},
|
||||||
'start': {'required': True},
|
'start': {'required': True},
|
||||||
'slug': {'required': False},
|
'slug': {'required': False},
|
||||||
|
|
|
||||||
|
|
@ -100,9 +100,48 @@ class CollectionBackOfficeList(CollectionBackOfficeViewSet):
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
|
|
||||||
|
|
||||||
class GuideListCreateView(GuideBaseView,
|
class GuideListCreateView(GuideBaseView, generics.ListCreateAPIView):
|
||||||
generics.ListCreateAPIView):
|
"""
|
||||||
"""View for Guides list for BackOffice users and Guide create."""
|
## 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
|
filter_class = filters.GuideFilterSet
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user