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-07-28 12:08:07 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
bcdde74b4192c8e40645fb5dea997c2a635be37f
bcdde74b
1 parent
f49ca13d
reformateo_de_funcion_por_constante
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
6 deletions
project/apps/edicto/constants.py
project/apps/edicto/models.py
project/apps/edicto/serializer.py
project/apps/edicto/constants.py
View file @
bcdde74
...
...
@@ -14,3 +14,5 @@ STATUS_CHOICE = [
(
APROBADO
,
_
(
'aprobado'
)),
(
RECHAZADO
,
_
(
'rechazado'
)),
]
EXTENSIONES_VALIDAS
=
[
".pdf"
,
".docx"
,
".jpg"
,
".jpeg"
,
".png"
]
...
...
project/apps/edicto/models.py
View file @
bcdde74
from
django.db
import
models
from
.utils
import
valid_extension
from
.constants
import
STATUS_CHOICE
from
usuario.models
import
Usuario
# Create your models here.
...
...
@@ -29,7 +26,7 @@ class Precio (models.Model):
class
Edicto
(
models
.
Model
):
usuario
=
models
.
ForeignKey
(
Usuario
,
on_delete
=
models
.
CASCADE
,
verbose_name
=
'Usuario'
,
null
=
True
)
cuerpo_edicto
=
models
.
TextField
(
blank
=
False
,
null
=
False
)
archivo
=
models
.
FileField
(
upload_to
=
"uploads/
%
Y/
%
m/
%
d/"
,
null
=
False
,
blank
=
False
,
validators
=
[
valid_extension
]
)
archivo
=
models
.
FileField
(
upload_to
=
"uploads/
%
Y/
%
m/
%
d/"
,
null
=
False
,
blank
=
False
)
dias_publicar
=
models
.
PositiveIntegerField
(
blank
=
False
,
null
=
False
)
cantidad_sellos
=
models
.
PositiveIntegerField
(
blank
=
False
,
null
=
False
)
estado
=
models
.
CharField
(
max_length
=
150
,
choices
=
STATUS_CHOICE
,
default
=
'inciado'
)
...
...
project/apps/edicto/serializer.py
View file @
bcdde74
from
rest_framework
import
serializers
from
.constants
import
EXTENSIONES_VALIDAS
from
.models
import
Edicto
...
...
@@ -10,7 +10,9 @@ class EdictoSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
Edicto
fields
=
(
'cuerpo_edicto'
,
fields
=
(
'usuario'
,
'cuerpo_edicto'
,
'estado'
,
'cantidad_palabras'
,
'dias_publicar'
,
'cantidad_sellos'
,
...
...
@@ -18,3 +20,10 @@ class EdictoSerializer(serializers.ModelSerializer):
'fecha_publicacion'
,
'archivo'
,
'fecha_creacion'
,)
@staticmethod
def
validate_archivo
(
value
):
filename
,
extension
=
value
.
name
.
rsplit
(
"."
,
1
)
if
extension
.
lower
()
not
in
EXTENSIONES_VALIDAS
:
raise
serializers
.
ValidationError
(
"Archivos permitidos: .pdf, .docx, .jpg, .jpeg, .png"
)
return
value
...
...
Please
register
or
login
to post a comment