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

34πŸ‘

βœ…

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().

πŸ‘€Ismail Badawi

Leave a comment