Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Marta Miranda
/
boletin_api
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Enzo Yair
2023-08-28 11:14:09 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
27d02d28dffcfe2ab56aa789afc74a1ac5ee5d3e
27d02d28
1 parent
73115c90
Se agrego filtros a edictoviewset
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
34 deletions
project/apps/edicto/api.py
project/apps/edicto/filters.py
project/apps/edicto/serializer.py
project/apps/edicto/api.py
View file @
27d02d2
from
rest_framework
import
viewsets
,
mixins
,
status
,
serializers
from
rest_framework
import
viewsets
,
filters
,
mixins
,
status
,
serializers
from
django_filters.rest_framework
import
DjangoFilterBackend
from
rest_framework.response
import
Response
from
rest_framework.permissions
import
IsAuthenticated
from
rest_framework.decorators
import
action
...
...
@@ -6,6 +7,7 @@ from datetime import datetime
from
.models
import
Edicto
,
Precio
from
.serializer
import
EdictoSerializer
,
PrecioSerializer
from
.filters
import
EdictoFilter
from
.utils
import
contador
# from .precio import contador
...
...
@@ -19,39 +21,17 @@ class EdictoViewSet(mixins.CreateModelMixin,
serializer_class
=
EdictoSerializer
permission_classes
=
[
IsAuthenticated
,
]
def
get_queryset
(
self
):
return
Edicto
.
objects
.
all
()
.
order_by
(
'usuario_id'
)
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
fields_to_select
=
[
'id'
,
'estado'
,
'cuerpo_edicto'
,
'cantidad_palabras'
,
'dias_publicar'
,
'cantidad_sellos'
,
'cantidad_copias'
,
'archivo'
,
'fecha_creacion'
,
'observaciones'
,
'fecha_publicacion'
,
]
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
()
.
values
(
*
fields_to_select
))
user_id
=
request
.
user
.
id
response_data
=
{
'user_id'
:
user_id
,
'edictos'
:
queryset
,
}
return
Response
(
response_data
)
filter_backends
=
(
DjangoFilterBackend
,
filters
.
OrderingFilter
)
filterset_class
=
EdictoFilter
queryset
=
Edicto
.
objects
.
all
()
.
order_by
(
'id'
)
ordering_fields
=
(
'usuario'
,
'estado'
,
'fecha_publicacion'
,
'id'
,)
def
perform_create
(
self
,
serializer
):
edicto
=
self
.
request
.
data
.
get
(
'cuerpo_edicto'
)
cantidad_palabras
=
contador
(
edicto
)
serializer
.
save
(
cantidad_palabras
=
cantidad_palabras
,
usuario
=
self
.
request
.
user
)
@action
(
detail
=
True
,
methods
=
[
'patch'
])
@action
(
detail
=
True
,
methods
=
[
'p
ut'
,
'p
atch'
])
def
custom_update
(
self
,
request
):
edicto
=
request
.
data
.
get
(
'cuerpo_edicto'
)
cantidad_palabras
=
contador
(
edicto
)
...
...
project/apps/edicto/filters.py
View file @
27d02d2
...
...
@@ -3,6 +3,11 @@ from django_filters import rest_framework as filters
from
edicto.models
import
Edicto
class
EdictoFilters
(
filters
.
FilterSet
):
models
=
Edicto
fields
=
(
'estado'
,
'fecha_publicacion'
,)
class
EdictoFilter
(
filters
.
FilterSet
):
class
Meta
:
models
=
Edicto
fields
=
(
'usuario'
,
'estado'
,
'fecha_publicacion'
,
'edicto_id'
,)
...
...
project/apps/edicto/serializer.py
View file @
27d02d2
...
...
@@ -12,6 +12,7 @@ class EdictoSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
Edicto
fields
=
(
'edicto_id'
,
'usuario'
,
'estado'
,
'cuerpo_edicto'
,
'cantidad_palabras'
,
...
...
@@ -21,13 +22,14 @@ class EdictoSerializer(serializers.ModelSerializer):
'archivo'
,
'fecha_creacion'
,
'observaciones'
,
'fecha_publicacion'
,
)
included_serializers
=
{
'usuario'
:
'usuario.serializers.UsuarioSerializer'
,
'usuario'
:
UsuarioSerializer
,
}
read_only_fields
=
(
'fecha_publicacion'
,
'cantidad_palabras'
,
'fecha_creacion'
)
read_only_fields
=
(
'
usuario'
,
'
fecha_publicacion'
,
'cantidad_palabras'
,
'fecha_creacion'
)
def
to_representation
(
self
,
instance
):
data
=
super
()
.
to_representation
(
instance
)
...
...
@@ -44,7 +46,6 @@ class EdictoSerializer(serializers.ModelSerializer):
return
value
class
PrecioSerializer
(
serializers
.
ModelSerializer
):
usuario
=
UsuarioSerializer
()
...
...
Please
register
or
login
to post a comment