0

is there a way to combine those 2 lines of code?

a = terminal.provisioning_set.first()
b = a.usergroup.id

the result is coming from:

 terminal = Terminal.get_object(terminal_id, request.user)

I like to see something like this:

result = terminal.provisioning_set.first(usergroup.id)

1 Answers1

0

first() doesn't accept any arguments. Docs

first() - Returns the first object matched by the queryset, or None if there is no matching object.

So what you've shown is incorrect.

You can try like this.

result = terminal.provisioning_set.first().usergroup.id
Ram
  • 4,724
  • 2
  • 14
  • 22