Django ORM - Select and Output individual fields example

Django ORM - Select and Output individual fields example

Very Academy

3 года назад

15,780 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Z Z
Z Z - 12.05.2023 23:27

How can I sort the posts of one user, for example, I only want to display the posts of a user who uploaded them on his own account, like the technology in Facebook, that is, when I upload a post, I can see it on my own page, I want to do something similar to that But I haven't succeeded yet

Ответить
Guido Michael
Guido Michael - 02.02.2023 09:45

It is interesting. If I select only the firstname and the age it is also possible to display the surename and the classroom. The SQL querie ('sql': 'SELECT "student_student"."id", "student_student"."firstname", "student_student"."age" FROM "student_student" WHERE "student_student"."classroom" = 1)

calls only the firstname and age but its seems to take the whole instance ...
So what does the ".only()" do?

Ответить
Mr.Anderson
Mr.Anderson - 30.10.2022 09:36

students = Student.objects.filter(class_room=2).only('first_name') also gives last name as well.

Ответить
CantControl
CantControl - 13.01.2022 21:41

but in my case it is still access all data from post ???????????
posts = User.objects.filter(last_name__contains='Khan').only("username", "email")

Ответить
UVTALKS
UVTALKS - 13.11.2021 14:09

Use have solved my biggest problem of working with database in django. Please Make Videos on other methods(like select_related,exclude) also.

Ответить
Taddele Petros
Taddele Petros - 29.07.2021 21:46

this is great thank you

Ответить
Julien Boudreau
Julien Boudreau - 27.06.2021 17:42

This is a great series. It's great to slow down and focus on one aspect of Django.

Ответить
Coşkun Deniz
Coşkun Deniz - 17.05.2021 21:23

thanks very much for this series

Ответить
createlyf
createlyf - 06.11.2020 12:05

Can we see a video on select_related and prefetch_related.?

Ответить