On 13/05/2018 5:00 AM, Alexander Joseph wrote:
I'm building a timesheet app for employees and would like the employees to be able to select a day of the week date based on what the date was on Monday.

ie. the user inputs the Monday date of the timesheet, then for each row they need to fill out they can select the Day/Date for each day that week so that those hours they input get assigned to that specific day/date. The easiest way I can think of would be to make a list of choices in the Model such as ...

|
MONDAY = 'MO'
TUESDAY = 'TU'
WEDNESDAY = 'WE'
THURSDAY = 'TH'
FRIDAY = 'FR'
SATURDAY = 'SA'
SUNDAY = 'SU'

DAY_CHOICES = (
    (MONDAY, 'Monday'),
    (TUESDAY, 'Tuesday'),
    (WEDNESDAY, 'Wednesday'),
(THURSDAY, 'Thursday'),
(FRIDAY, 'Friday'),
(SATURDAY, 'Saturday'),
(SUNDAY, 'Sunday'),
)
day = models.CharField(
    max_length=2,
choices=DAY_CHOICES,
    default=MONDAY,
)
|

This would work except I also want to include the actual date of the day they select, based on the Monday date that they put in in another Model

Is there a library or package I can use to do this?

Not sure. Have a look at baklabel, a utility I wrote many years ago and while I use it every day I haven't looked at it in living memory. Source is at https://pypi.org/project/baklabel/#files

It takes a date and returns a string being 'mon', tue' and so on except 'fri1', 'fri2' etc and it also cares about end-of-month and end-of-year. The string is intended as a path fragment for labelling scripted backups.

The settings/options will allow a much more vanilla return string. You could stop it counting fridays and omit end-of-month and end-of-year detection.

The date arithmetic in there might be useful and extractable as separate library.


Thanks!
--
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6089eafa-7495-4ec4-a539-624cf95014b0%40googlegroups.com <https://groups.google.com/d/msgid/django-users/6089eafa-7495-4ec4-a539-624cf95014b0%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/74e0e602-858e-85ad-3e87-8c69577d0ba9%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to