Update dictionary value in class a from class b-Python

55 Views Asked by At

I set multi dictionary in my constant class and need to update it several times on different pages based on different logic on each page. However, when I retrieve instances of my dictionary that I updated on my HTML page, I get initial values. I cannot figure out the problem and why the dictionary does not update...

class Constants(BaseConstants):
   items = ["item1", "item2", "item3", "item4", "item5"]

   months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
   projected_balance = {
        "Jan": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "Feb": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "Mar": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "Apr": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "May": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "Jun": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "Jul": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "Aug": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "Sep": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "Oct": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "Nov": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0},
        "Dec": {"item1": 0, "item2": 0, "item3": 0, "item4": 0, "item5": 0}}

class Period1(Page):
...
    def vars_for_template1(player: Player):
    items = ["item1", "item2", "item3", "item4", "item5"]
    months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

    for month in months:
        for item in items:
            Constants.projected_balance.update({[month][item] :  Constants.inventory[month][item] + Constants.scheduled_receipt[month][item]- Constants.forecast[month][item]})
0

There are 0 best solutions below