[Answer]-Django how can i use variable in get query?

1👍

jgrp = group.objects.get(groupname=juser.group)

This code is perfectly valid. problem is, there is no corresponding group object for your account.group value.

I also think that your data model is not really ideal for a relational db. I think you should have a foreign key from your account model to group model so you can just use juser.group as @knapo suggested.

0👍

group is an object and you need the name of the group. So probally =juser.group.name

0👍

I think all you need to do is to replace the last line with this:

jgrp = juser.group

Leave a comment