See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Django - create dictionary of associated objects

General Tech Technology & Software
Max. 2000 characters

Yasmin Mirza


( 4 months ago )


I'm attempting to build a query which will return a list of all technologies and the score of each user associated with each technology. This is based on the following models:

class Technology(models.Model):
    technology = models.CharField(max_length=64)

class Result(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    technology = models.ForeignKey(technology, on_delete=models.CASCADE)
    skill_level = models.ForeignKey(skill, to_field='level', on_delete=models.CASCADE)

class Skill(models.Model):
    level = models.IntegerField(unique=True)

Essentially I'd like to see somthing similar to the following:

{technology: Cisco, users: {Alex: {skill_level: 1}}, {James: {skill_level: 2}}

I'm not sure whether this can be acheived with a simple query or whether custom joins will need to be done?

I'm also not sure whether I should be building this on the Technologymodel or the Result model?

what's your interest