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-10-05 10:10:40 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
529dac17da50ffb88d2f11407fd7c26e5fc1b19f
529dac17
1 parent
b06e1aef
validacion para la creacion de precio admin
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
project/apps/edicto/admin.py
project/apps/edicto/admin.py
View file @
529dac1
from
django.contrib
import
admin
from
django.contrib
import
admin
,
messages
from
.models
import
Edicto
,
Precio
# Register your models here.
...
...
@@ -6,16 +7,18 @@ from .models import Edicto, Precio
class
PrecioAdmin
(
admin
.
ModelAdmin
):
def
save_model
(
self
,
request
,
obj
,
form
,
change
):
if
change
:
super
()
.
save_model
(
request
,
obj
,
form
,
change
)
else
:
precios_con_vigencia
=
Precio
.
objects
.
exclude
(
vigencia_hasta
=
None
)
.
count
(
)
precios_con_vigencia
=
Precio
.
objects
.
filter
(
vigencia_hasta__isnull
=
True
)
if
precios_con_vigencia
>
0
and
obj
.
vigencia_hasta
is
None
:
form
.
add_error
(
'vigencia_hasta'
,
if
precios_con_vigencia
:
messages
.
error
(
request
,
'Error al agregar: Ya existe un objeto Precio sin vigencia_hasta. '
'Debe proporcionar una fecha para vigencia_hasta antes de crear un nuevo objeto Precio.'
)
else
:
messages
.
success
(
request
,
'El nuevo precio se agrego correctamente'
)
obj
.
usuario
=
request
.
user
super
()
.
save_model
(
request
,
obj
,
form
,
change
)
...
...
Please
register
or
login
to post a comment