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