Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python/Django date query: Unsupported lookup 'date' for DateField or join on the field not permitted

I have a simple method. Entries are entries in a time sheet application where employees enter their hours.

class Entry(m.Model):
    """ Represents an entry in a time_sheet. An entry is either for work, sick leave or holiday. """
    # type choices
    WORK     = 'w'
    SICK     = 's'
    VACATION = 'v'
    type_choices = (
        (WORK,     'work'),
        (SICK,     'sick leave'),
        (VACATION, 'vacation'),
    )
    # meta
    cr_date = m.DateTimeField(auto_now_add=True, editable=False, verbose_name='Date of Creation')  # date of creation
    owner   = m.ForeignKey(User, editable=False, on_delete=m.PROTECT)
    # content
    type    = m.CharField(max_length=1, choices=type_choices, default='w')
    day     = m.DateField(default=now)
    start   = m.TimeField(blank=True)  # starting time
    end     = m.TimeField(blank=True)  # ending time
    recess  = m.IntegerField()  # recess time in minutes
    project = m.ForeignKey(Project, on_delete=m.PROTECT)

    @classmethod
    def get_entries_for_day(cls, user, day):
        """ Retrieves any entries for the supplied day. """
        return Entry.objects.filter(day__date=day, owner=user).order_by('start')

However, when I try to run my project like this, it terminates with the following error code:

"Unsupported lookup 'date' for DateField or join on the field not permitted."

I don't quite understand the message. The specified field is a date field which has no further restrictions. Any hints would be appreciated.

like image 960
user2660930 Avatar asked Jun 22 '16 15:06

user2660930


1 Answers

There's no such thing as a __date lookup on a DateField; the field is already a date.

It's not clear what you are trying to compare this field with. Is the day you are passing into that method an integer, or a date? If it's also a date then you should just compare them directly.

like image 200
Daniel Roseman Avatar answered Sep 21 '22 01:09

Daniel Roseman