Merge branch 'feature/#73_validacion_en_precio_admin' into 'develop'
Feature/#73 validacion en precio admin See merge request !68
Showing
1 changed file
with
20 additions
and
2 deletions
1 | -from django.contrib import admin | 1 | +from django.contrib import admin, messages |
2 | 2 | ||
3 | from .models import Edicto, Precio | 3 | from .models import Edicto, Precio |
4 | 4 | ||
5 | # Register your models here. | 5 | # Register your models here. |
6 | 6 | ||
7 | 7 | ||
8 | -admin.site.register(Precio) | 8 | +class PrecioAdmin(admin.ModelAdmin): |
9 | + def save_model(self, request, obj, form, change): | ||
10 | + | ||
11 | + if change: | ||
12 | + super().save_model(request, obj, form, change) | ||
13 | + else: | ||
14 | + | ||
15 | + precios_con_vigencia = Precio.objects.filter(vigencia_hasta__isnull=True) | ||
16 | + | ||
17 | + if precios_con_vigencia: | ||
18 | + messages.error(request, 'Error al agregar: Ya existe un objeto Precio sin vigencia_hasta. ' | ||
19 | + 'Debe proporcionar una fecha para vigencia_hasta antes de crear un nuevo objeto Precio.') | ||
20 | + else: | ||
21 | + messages.success(request, 'El nuevo precio se agrego correctamente') | ||
22 | + obj.usuario = request.user | ||
23 | + super().save_model(request, obj, form, change) | ||
24 | + | ||
25 | + | ||
26 | +admin.site.register(Precio, PrecioAdmin) | ||
9 | 27 | ||
10 | admin.site.register(Edicto) | 28 | admin.site.register(Edicto) |
-
Please register or login to post a comment