diff --git a/offers/admin.py b/offers/admin.py index 16ef348..2b28bde 100644 --- a/offers/admin.py +++ b/offers/admin.py @@ -10,13 +10,13 @@ class OffersAdmin(admin.ModelAdmin): def pub_date(self, obj): - return obj.published_date.strftime("%d/%M/%Y") + return obj.published_date.strftime("%d/%m/%Y") def begin_date_format(self, obj): - return obj.begin_date.strftime("%d/%M/%Y") if obj.begin_date else '' + return obj.begin_date.strftime("%d/%m/%Y") if obj.begin_date else '' def end_date_format(self, obj): - return obj.end_date.strftime("%d/%M/%Y") if obj.end_date else '' + return obj.end_date.strftime("%d/%m/%Y") if obj.end_date else '' list_display = ('provider', 'title', 'active', 'pub_date', 'begin_date_format', 'end_date_format') ordering = '-published_date', diff --git a/offers/migrations/0003_set_offer_date_to_current_date_as_default.py b/offers/migrations/0003_set_offer_date_to_current_date_as_default.py new file mode 100644 index 0000000..e2ddd71 --- /dev/null +++ b/offers/migrations/0003_set_offer_date_to_current_date_as_default.py @@ -0,0 +1,24 @@ +# Generated by Django 5.0 on 2024-03-19 12:59 + +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('offers', '0002_alter_offer_title'), + ] + + operations = [ + migrations.AlterField( + model_name='offer', + name='begin_date', + field=models.DateField(blank=True, default=django.utils.timezone.now, null=True, verbose_name='Fecha de inicio'), + ), + migrations.AlterField( + model_name='offer', + name='end_date', + field=models.DateField(blank=True, default=django.utils.timezone.now, null=True, verbose_name='Fecha de fin'), + ), + ] diff --git a/offers/models/offer.py b/offers/models/offer.py index bc4a98e..47a0aa3 100644 --- a/offers/models/offer.py +++ b/offers/models/offer.py @@ -1,5 +1,7 @@ import uuid + +from django.utils import timezone from django.utils.translation import gettext as _ import datetime from django.db import models @@ -64,8 +66,8 @@ class Offer(models.Model): discount_percent = models.FloatField(null=True, blank=True, verbose_name=_('Porcentaje de descuento'), default=0) discounted_price = models.FloatField(null=True, blank=True, verbose_name=_('Precio con descuento'), default=0) active = models.BooleanField(default=True, null=False, verbose_name=_('Activa')) - begin_date = models.DateField(null=True, blank=True, verbose_name=_('Fecha de inicio')) - end_date = models.DateField(null=True, blank=True, verbose_name=_('Fecha de fin')) + begin_date = models.DateField(null=True, blank=True, default=timezone.now, verbose_name=_('Fecha de inicio')) + end_date = models.DateField(null=True, blank=True, default=timezone.now, verbose_name=_('Fecha de fin')) objects = OffersManager()