T
T
Tihon492020-08-26 10:25:13
Django
Tihon49, 2020-08-26 10:25:13

What is this construct: shop, _ = Shop.objects.get.... blah blah blah....?

In the online store project on django, I saw the following construction:

shop, _ = Shop.objects.get_or_create(name=data['shop'], user_id=request.user.id)


what happens after the "=" sign is clear, but it is not clear why it is written in this way:shop, _ =

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-08-26
@Tihon49

Most likely, the get_or_create method returns an array (tuple) with two values, where the first element is written to the shop variable, and the second is simply not needed, so it is simply ignored with
_UPD. Here is what I found in the documentation: https://djbook.ru/rel1.7/ref/models/querysets.html...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question