Skip to content

Commit

Permalink
Set current date as default when creating an offer
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoMoreta committed Mar 19, 2024
1 parent 857d18e commit 38214f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
6 changes: 3 additions & 3 deletions offers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
),
]
6 changes: 4 additions & 2 deletions offers/models/offer.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 38214f0

Please sign in to comment.