'Need to display the hours spent in the date from one model to another

model 1

class Add_Timelog(models.Model):
 
    project=models.ManyToManyField(Project)
    client=models.ManyToManyField(Client)
    Job=models.ManyToManyField(Add_Job)
    Date= models.DateField(default = datetime.date.today)
    Hours=models.TimeField(null=True)
    
    def __str__(self):
        return str(self.Date)

model 2

class Consolidated(models.Model):
    
    emp_name=models.ManyToManyField(Users,related_name="employee_name+")
    proj_name=models.ManyToManyField(Project)
    custom_name=models.ManyToManyField(Client)
    Cons_date=models.ManyToManyField(Add_Timelog)
    bill_no_bill=models.ManyToManyField(Users,related_name="billable_and_non_billable+")
    hours_spent = models.ManyToManyField(Add_Timelog,related_name="Hours+")

    def __str__(self):
       return str(self.id)

I need to update the value from "Hours" field in Add_Timelog model to display it in the "hours_spent" field in Consolidated model. As I am already doing it for "Date" field I need to do it for this also. But I don't know whether it can be possible, kindly help me with this code.

(ex: if I enter a Date as today and Hours as 4 hr's in Add_Timelog model, I need to display it in Consolidated model as for today 4 hr's has been spent by this employee.)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source