Skip to content

Tag: django

A count of ForeignKey

I have class Team, which means a group of users. And the relation with User is One-to-Many. But Team may consist of 2 and N members. I think to write manually is not our way, because it depends on count of people which is always variable. How can I do it more elegant and rational? I mean to connect count

Date filter binned data

I have a model in django that contains a start and end date for a financial year and a value for demand volume. I would like to filter this data on a given date range that may not coincide with the date ranges of the data, taking a proportion of the demand from each data point that may fall somewhere

How can I use map operator with for loop?

I have a function that returns a list of the total counts. I want to use the map but don’t know how I can use it. Here is my function: I want to use this with the map. Answer I don’t think it’s neccessary. you are just constantly adding terms, so it’s just a sum and it doesn’t re…

Django 4.x – Conditional order_by of a QuerySet

The Objective The objective is to conditionally order a QuerySet by one of three different date fields in the view based on another field in the model. Since conditional ordering cannot be accomplished with Class Meta I am exploring accomplishing this objective in the view. Here is the relevant excerpt from m…