简体   繁体   中英

Need to Fetch datetime input from one model and post it as a day in another model API using Django

Need to fetch the Date entered in the below model Timesheet and display it as Day in a new model as a api

#Model class Timesheet(models.Model):

Date=models.DateField()

Hours=models.TimeField(null=True)

def __str__(self):
    return self.id

Need help on creating a report table day wise(example: if we enter a date as 28.01.2022, it needs to display as Friday in the new model).

This should give you the day. You can use this method to assign day in another model also as your necessity.

from datetime import date
import calendar
def __str__(self):
    return calendar.day_name[self.Date.weekday()]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM