MiniGunnR
MiniGunnR

Reputation: 5800

Why is the week_day API not working on a model method in Django?

model

class Attn(Timestamp):
    dt = models.DateField()

    @property
    def saturday(self):
        return self.dt__week_day == 7

I am trying to find the number of entries in the model that was a Saturday. I found the API from here. So I made a list comprehension as following.

view

len([1 for i in attns if i.saturday])

When I run the view it shows AttributeError.

'Attn' object has no attribute 'dt__week_day'

What am I doing wrong here?

Upvotes: 0

Views: 39

Answers (1)

pramod
pramod

Reputation: 1493

class Attn(Timestamp):
    dt = models.DateField()

    @property
    def saturday(self):
        return self.dt.weekday() == 7

>>> sum(1 for i in attns if i.saturday)

Upvotes: 2

Related Questions