Once you’ve done that for all the fields, you can then pass totals_dict into your template through the context, accessing it from the template as totals_dict.cashbal.
Any one of those options can be used to obtain the desired results.
As a side note, it’s become apparent to me that you’re working with “money” as a fundamental type. You never, never, never want to use a FloatField when working with currency values. The only valid approach to working with money is to use a DecimalField.
I am having negative ( Incomes & Expenses) and positive values, initially I tried DecimalField, it throwed error while saving, that’s why I changed to FloatField.
Let me try it back again and will update.
I am just trying to record daily expenses ( personal ).
Add Values in my own form
Get reporting done by filters like payment mode.
Also I need reporting based on Months.
Multiple page reports having Header grouped by months, month vise totals, totals based on payment mode.
Still need to go long, meanwhile I want to learn compact coding, mine looks very messy for me.
Thanks for your continues support.
About the four different suggestions, please show me some more light, How I can modify or restructure.
What do your queries return? How can you change your query to return what you want?
Again, play with this in the shell. Look at what totals_dict looks like. What can you do to change the structure?
In general Python terms (not Django terms - this has nothing to do specifically with Django), what does **kwargs represent in a function call?
How do you access an element of a dictionary in your template?
Compact is not always better. Yes, this code can be shortened even further - and some might call it “better” - but doing so may make it less clear. (e.g. You can apply multiple aggregates in one aggregate function call.)
Never forget that Django is just Python. Anything you can do in Python can be done in Django. If Django doesn’t appear to provide a function or feature that would be helpful to you, look at the wider Python library.
Given a elaborated reply ( guide ).
I will start learning what all you have mentioned.
Once I have fine tuned my project, will post back for your guidance.