Ali Hasan
delete the last migrations and try again
deleting or uninstalling the django-silk solves the problem so I don't think deleting migrations would solve the problem ?
Д
Or you have mistyped the package name
Ali Hasan
Thanks a million !!
C
Can any share code of ajax code for dropdown with changing of charts
Harry gorilla
I struggled a lot learning this way. but it comes around a bit by bit doing some searching along the way
Sure, thanks. Though after learning python, things start to become confusing along the way
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
Harry gorilla
It's being passed by reference
https://realpython.com/python-pass-by-reference/ Is this the pass by reference you are talking about?
Д
https://realpython.com/python-pass-by-reference/ Is this the pass by reference you are talking about?
Yes but the most critical part is that the function (the address of the function) is being passed
Д
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
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?
in settings.py you have to write your app under INSTALLED_APPS include the string " apps.apps.AppsConfig"
Arpit
I did this.. But idk why it's now working :/
refer to this https://docs.djangoproject.com/en/4.0/ref/applications/
Harry gorilla
Try: thing = print thing("what happens?")
from here, for the message hello, world to be displayed, the homePageView function has to be called right?
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
django will get to that call on its own good time, yes
I think learning django with a python mind is a bad idea, many things won't just make sense even if you understand python so well
Д
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
that's not really what you asked. go read the documentation
Ah sorry if there's any misunderstanding but that was my question and I even provided my line of query. Anyway I'll keep digging and thanks a lot of your efforts 🙏🏻
Ali Hasan
you were basically asking "why isn't prefetch_related doing what I think it's doing"
oh yeah which is doing the joins for many to one or many to many(basically)
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
the documents seem to explain the thing. I didn't know the difference before this and I went and copypasted you the explanation
the thing is documentation becomes the nightmare for (1- beginners, 2- non-native english speakers) 😂 .
Ali Hasan
Д
I don't know how to fix it but it has to do with select_related?
Ali Hasan
I don't know how to fix it but it has to do with select_related?
I'm trying to make my way around it by testing actually, once I hit the minimal number of queries generated, then I'll say booom I got it
Д
load the whole database into memory ;)
Д
problem solved
Ali Hasan
load the whole database into memory ;)
😂😂😂 might be done without the intention to do it haha
Harry gorilla
I have seen alot of people who are good in django and don't know python in advance
Д
I have seen alot of people who are good in django and don't know python in advance
if learning to develop websites motivates people to learn to program, why not :)
Д
I have seen alot of people who are good in django and don't know python in advance
you can view Django pretty much from a 'functional' point of view. there are parameters you pass to the correct things and then they do their thing, and things work
Д
you can view Django pretty much from a 'functional' point of view. there are parameters you pass to the correct things and then they do their thing, and things work
of course you HAVE to know what precise order things happen in, and sometimes more computer-sciencey things DO pop-up but generally it's not as 'low level' as many other types of programming
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.
Д
to abstract those things away from the actual work you want to do
in the history of CS has there ever been a framework that has managed to do that 100%
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
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
cj
Advance python or just a little bit of python
enough Python to use it with a framework like Django... basic is not enough ¯\_(ツ)_/¯
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—
Ali Hasan
yeah it might go pretty ass-backwards
Do you know I would burn any server if it was given to me ? LOL check this out
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 ?
Mosihere
I just find django somehow not related to python in some way. Like for instance, the django classes python classes normally have the init function, django classes in the model does not
If you check the source code, you'll find out it has an init method we normally don't use it in models if you look carefully, you'll understand in model classes our class inherit from models.Model and that Model object of course has an init constructor method
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