[Fixed]-Django 'dict' object has no attribute 'user_id'


The .values() method on querysets returns a queryset that returns dictionaries instead of model objects when you iterate over it — so user_who_played is a dict, which means you should access the user id by writing user_who_played['user_id'] instead of using dot attribute syntax.

If you want to retrieve only certain fields from the database but still want to deal with model objects, an alternative is to use the .only() method instead of .values().

Leave a comment