Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding name col to CrontabSchedule model #478

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
18 changes: 18 additions & 0 deletions django_celery_beat/migrations/0016_crontabschedule_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.7 on 2021-12-15 13:06
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use django 3.2.x to regenerate this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-created with 3.2

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trianglesis It doesn't seem necessary to do the if twice. I'll checkout your branch in my projects.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good


from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('django_celery_beat', '0015_edit_solarschedule_events_choices'),
]

operations = [
migrations.AddField(
model_name='crontabschedule',
name='name',
field=models.CharField(blank=True, help_text='Short Description For This Cron Schedule', max_length=200, null=True, verbose_name='Name'),
),
]
17 changes: 15 additions & 2 deletions django_celery_beat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ class CrontabSchedule(models.Model):
'Timezone to Run the Cron Schedule on. Default is UTC.'),
)

name = models.CharField(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would also like to have unit tests for new proposed changes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't run any test from test_schedulers.py with the current setup.
Will try to figure out what am I doing wrong, and possibly add some tests.

max_length=200, unique=False,
null=True, blank=True,
verbose_name=_('Name'),
help_text=_('Short Description For This Cron Schedule'),
)

class Meta:
"""Table information."""

Expand All @@ -308,10 +315,16 @@ class Meta:
'day_of_week', 'hour', 'minute', 'timezone']

def __str__(self):
return '{0} {1} {2} {3} {4} (m/h/dM/MY/d) {5}'.format(

name = None
if self.name:
name = '[{}]'.format(self.name)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I wanted to achieve [Name in brackets], but leave an empty '' if there is no name.
Making if and if - makes it more visible on code, but It could be changed back to 1st version.
Thanks!


return '{0} {1} {2} {3} {4} (m/h/dM/MY/d) {5} {6}'.format(
cronexp(self.minute), cronexp(self.hour),
cronexp(self.day_of_month), cronexp(self.month_of_year),
cronexp(self.day_of_week), str(self.timezone)
cronexp(self.day_of_week), str(self.timezone),
name if name else '',
)

@property
Expand Down