Showing
1 changed file
with
7 additions
and
4 deletions
1 | -from django.contrib import admin | 1 | +from django.contrib import admin, messages |
2 | + | ||
2 | from .models import Edicto, Precio | 3 | from .models import Edicto, Precio |
3 | 4 | ||
4 | # Register your models here. | 5 | # Register your models here. |
@@ -6,16 +7,18 @@ from .models import Edicto, Precio | @@ -6,16 +7,18 @@ from .models import Edicto, Precio | ||
6 | 7 | ||
7 | class PrecioAdmin(admin.ModelAdmin): | 8 | class PrecioAdmin(admin.ModelAdmin): |
8 | def save_model(self, request, obj, form, change): | 9 | def save_model(self, request, obj, form, change): |
10 | + | ||
9 | if change: | 11 | if change: |
10 | super().save_model(request, obj, form, change) | 12 | super().save_model(request, obj, form, change) |
11 | else: | 13 | else: |
12 | 14 | ||
13 | - precios_con_vigencia = Precio.objects.exclude(vigencia_hasta=None).count() | 15 | + precios_con_vigencia = Precio.objects.filter(vigencia_hasta__isnull=True) |
14 | 16 | ||
15 | - if precios_con_vigencia > 0 and obj.vigencia_hasta is None: | ||
16 | - form.add_error('vigencia_hasta', | 17 | + if precios_con_vigencia: |
18 | + messages.error(request, 'Error al agregar: Ya existe un objeto Precio sin vigencia_hasta. ' | ||
17 | 'Debe proporcionar una fecha para vigencia_hasta antes de crear un nuevo objeto Precio.') | 19 | 'Debe proporcionar una fecha para vigencia_hasta antes de crear un nuevo objeto Precio.') |
18 | else: | 20 | else: |
21 | + messages.success(request, 'El nuevo precio se agrego correctamente') | ||
19 | obj.usuario = request.user | 22 | obj.usuario = request.user |
20 | super().save_model(request, obj, form, change) | 23 | super().save_model(request, obj, form, change) |
21 | 24 |
-
Please register or login to post a comment