[Fixed]-Need to access the username in a function

1👍

The simplest thing is just to pass the user to the class initialiser.

def __init__(self, holiday, user):
    super(HolidayCalendar, self).__init__()
    self.user = user
    self.holiday = self.holiday_days(holiday)

def formatday(self, day, weekday):
    ...
    if holiday_object.person_id == self.user:

and in your view:

cal = HolidayCalendar(my_holidays, request.user).formatmonth(year, month)

Leave a comment