Dictionaries are just better resilent arrays with a search complexity O(1). I was working with scriptable objects and found out the hard way that unity doesnt save variables in scriptable objects that cannot be serialized. Had to use Odin Inspector's custom scriptable object for a quick workaround.
I'm sure theres a good reason to not serialize dictionaries... but cant think of any reason not to.
Dictionary serialization with UIElement? - Unity Engine - Unity Discussions
Why doesn't Unity try to make the Dictionary and Stack Serializable? - Unity Engine - Unity Discussions
[Released] Dictionaries are now supported !!!! :D - Unity Engine - Unity Discussions
Serialize a Dictionary - Questions & Answers - Unity Discussions
Videos
The root problem here is that you don't understand why you are getting the error
name 'publisher__stats__elapsed_time_in_seconds' is not defined`.
Let's look at the code again:
Article.objects.filter(created_on__lte=datetime.now(timezone.utc) -
timedelta(hours=0, minutes=0, seconds=publisher__stats__elapsed_time_in_seconds))
In the code above the symbol publisher__stats__elapsed_time_in_seconds is interpreted as a variable reference, which is not defined in your code. If you added
publisher__stats__elapsed_time_in_seconds = 1
just before the code snippet above, then you would not get the error. (You would also not get the results you want.) You're expecting Django's ORM to operate on the symbol publisher__stats__elapsed_time_in_seconds but before Django can get to it, the Python interpreter must interpret the code, and the way the code is written, that's just a variable name which the interpreter must resolve. Django does not get a chance to even see it.
Ok so the way to prevent the interpreter to interpret the name as a variable reference, and have Django ORM's process the name, is to use F() expressions. So you'd be tempted to just do this:
Article.objects.filter(created_on__lte=datetime.now(timezone.utc) -
timedelta(hours=0, minutes=0, seconds=F("publisher__stats__elapsed_time_in_seconds")))
But then you'd be passing to timedelta a parameter it does not know how to handle.
As schillingt pointed out in a comment, an answer elsewhere by Lutz Prechelt shows how to move the F() expression outside the timedelta. In your case, you could do this:
Article.objects.filter(created_on__lte=datetime.now(timezone.utc) -
timedelta(seconds=1) * F("publisher__stats__elapsed_time_in_seconds"))))
Based on your publisher model, there is a problem on how you are defining the field to compare with. Your field in the question is
publisher__stats__elapsed_time_in_seconds
Your query code is
Article.objects.filter(created_on__lte=datetime.now(timezone.utc) - timedelta(hours=0, minutes=0, seconds=publisher__stats__elapsed_time_in_seconds)).
This basically means get me all articles that have a creation time(created_on field) before or exactly equal to the time(elapsed_time_in_seconds field) for the article-->publisher-->stats record.
This means it looks for a elapsed_time_in_seconds field on the stats object which should be related to your publisher object via a FK or some other way. The publisher object in turn needs to be related to your article object.
Your Article model is related to the Publisher model, but there does not seem to be a relation between the Publisher and the Stats (??). Can you check the stats model to see that the field and the relation is defined correctly?