Д
Д
Or you have mistyped the package name
Ali Hasan
Ali Hasan
Thanks a million !!
Enes
C
Can any share code of ajax code for dropdown with changing of charts
Harry gorilla
Harry gorilla
from django.urls import path
from .views import homePageView
urlpatterns = [
path("", homePageView, name="home"),
]
in this file, the path function is used to call the homePageView function. From my python knowledge, functions are not being called in this manner. I expected something like
path("", homePageView(), name="home"),
Harry gorilla
https://djangoforbeginners.com/hello-world/
That example is shown here
Д
Д
It's being passed by reference
Д
Try writing print(print)
Д
You asked how is that relevant?
Д
That way the object doesn't need to get created now. The function object has the prerequisite knowhow to create the new object with parameters that might not be known yet.
Д
The function object itself can now be parametrized further.
Enes
give me project ideas guys. I want to create something different. I bored to create e commerce blog projects
Д
Д
The function doesn't get called
Д
There is a new variable that contains the function like it was any variable
Д
Try:
thing = print
thing("what happens?")
Mohamad
RuntimeError: Model class apps.tasks.models.Task doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
What's the problem?
Arpit
Mohamad
Ali Hasan
I'm having two problems that are weird a bit although I'm following what I found online.
1-
sometimes MODEL.objects.prefetch_related(X).filter(X) isn't being accepted and should be filter then prefetch and sometimes not.
2-
I'm using django-silk to see how many queries my code is creating and found it's making 11 queries for the following code:
```branches = list(Branch.objects.all().prefetch_related('programs', 'programs__stages', 'department').filter(
department_id=request.auth['building_id']))```
Which is supposed to make one nested query right ? am I missing something here ?
Ali Hasan
Isn't prefetch related supposed to make it one query with lots of joins ?
Д
Д
Isn't prefetch related supposed to make it one query with lots of joins ?
prefetch_related, on the other hand, does a separate lookup for each relationship, and does the ‘joining’ in Python. This allows it to prefetch many-to-many and many-to-one objects, which cannot be done using select_related, in addition to the foreign key and one-to-one relationships that are supported by select_related.
Д
Harry gorilla
Ali Hasan
Д
What do you mean?
python defines something called the python object model. basically it means everything in python is an object, even things like basic numbers and strings. this is a very good example of it, where you can deal with functions by assigning them to variables or passing them to functions as if they were 'objects'
Д
Д
Ali Hasan
Ali Hasan
with one or maximum of 2-3 queries
Д
Д
the documents seem to explain the thing. I didn't know the difference before this and I went and copypasted you the explanation
Д
or something that directs you in the right direction at the very least
Ali Hasan
Ali Hasan
Д
I don't know how to fix it but it has to do with select_related?
Д
load the whole database into memory ;)
Д
problem solved
Harry gorilla
Д
Harry gorilla
I have seen alot of people who are good in django and don't know python in advance
Виктор
Д
Neo
ugh its the whole point of a framework
Neo
to abstract those things away from the actual work you want to do
Neo
you can always spin up an HTTP server in python and deal with everything on your own, not ideal though.
Harry gorilla
Sometimes back while i was learning django, i thought i was also learning python. Then i realised i was wrong i was learning no python in django
Д
Harry gorilla
I think now the only way to learn about django is to stop thinking that it's python
cj
cj
but to use it in a better way, you should know Python beforehand or you'll have some headaches
cj
Django is just a framework ¯\_(ツ)_/¯ if you don't know Python you'll have problems
Harry gorilla
cj
you can learn Python while you're learning Django at the same time... buuuuuut you'll find things a little bit hard/confusing than starting to learn Python first; it all depends on you ¯\_(ツ)_/¯
my recommendation is to first learn Python a little bit deeper and then start using Django —or any other framework/library you want—
Harry gorilla
Ali Hasan
Oh I forgot we can't send media here xD. anyway , I had a query that was executing 80 queries , after that it turns out it should only be 3 lol
Ali Hasan
I hope any body would explain this to me I really don't get it.
```students = Student.objects.select_related('department', 'stage', 'program','stage__program__branch')```
This generates the correct and minimal number of queries.
```
students = Student.objects.select_related('department', 'stage', 'program','program__branch')
```
This generates the correct result also but an extra query for each program and branch that is being fetched.
I don't get it because Student model has both (stage , program) as Foreign key fields. Program has the branch Foreign key in it.
Why is it different exactly ?
Lui
how and where to learn django?
Doragonsureiyā
how and where to learn django?
Looking for Django tutorials? you can follow these three recommended ones:
* Official documentation and tutorial
* Tutorial from MDN
* Tutorial from django-girls
Lui
Thanks
Harry gorilla
Sure, thanks