These are chat archives for django/django

23rd
Feb 2018
Renato C├ęsar
@rencesar
Feb 23 2018 00:22
Yeah?
Robert
@JaramilloRobert
Feb 23 2018 02:19
@JaramilloRobert
I need some help with getting templates to register
do i need to modify the settings.py file
that is on the same level of the manage.py file
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:19
can you more specific @JaramilloRobert ?
Robert
@JaramilloRobert
Feb 23 2018 02:19
Yeah
I keep getting an error
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:20
ok
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:20
do you need a folder called templates of the same level of manage.py?
Robert
@JaramilloRobert
Feb 23 2018 02:20
I have one under the gradebook app itself
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:21
what the structure ?
gradebook/templates/gradebook ?
and inside gradebook/templates/gradebook has init.py?
Robert
@JaramilloRobert
Feb 23 2018 02:21
yes
trying put up a pic now
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:21
dont'need pic
I need only of the your code on https://dpaste.de
of your view
Robert
@JaramilloRobert
Feb 23 2018 02:22
alright
what files
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:22
views.py
and urls.py
the request is redirect of logics put on urls.py and the logics put on urls.py is redirect to views.py :)
is the best flow to me to debug django projects
Robert
@JaramilloRobert
Feb 23 2018 02:23
here is the urls that are on mysite
Sorry on the app itself
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:24
nice I need too of the https://dpaste.de/NBRb#L23
Robert
@JaramilloRobert
Feb 23 2018 02:24
Sorry project
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:24
nice you are using django 2.0 :)
:clap:
Robert
@JaramilloRobert
Feb 23 2018 02:24

Here is the apps urls from django.urls import path
from . import views

urlpatterns = [
path('', views.index, name='index'),
path('class_summary,html', views.classSummary, name='Class Summary'), #<slug:class>

]

I am super new at this
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:25
I am seeing :p
you are function based views
Robert
@JaramilloRobert
Feb 23 2018 02:25
is that bad
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:25
path('class_summary,html', views.classSummary, name='Class Summary'), #<slug:class>
what is it ?
class_summary,html
why do you want to add ',html' on your url?
Robert
@JaramilloRobert
Feb 23 2018 02:26
Here are the urls for the gradebook app
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:27
I don't think so if it's is a good idea https://dpaste.de/GgJk#L6
but ok
give to me the views.py now
Robert
@JaramilloRobert
Feb 23 2018 02:28
here is the views
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:29
are you see that you are adding the ,html on your path?
please remove this from your urls.py
Robert
@JaramilloRobert
Feb 23 2018 02:29
do i not need to add .html
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:29
why?
Robert
@JaramilloRobert
Feb 23 2018 02:29
ok
Robert
@JaramilloRobert
Feb 23 2018 02:31
still dont hit it
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:31
add slash here
like https://dpaste.de/1cuZ#L23 @JaramilloRobert
Robert
@JaramilloRobert
Feb 23 2018 02:32
thanks man that worked
can i ask a clarifying question
1) is .html always assumed
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:33
so your problem was attention only this.
:)
is not a good idea
Robert
@JaramilloRobert
Feb 23 2018 02:33
2) we dont need to modify the template settings inside the project settings
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:33
if you want to get the first register of your db
you could use the https://dpaste.de/pZ3o#L11
Robert
@JaramilloRobert
Feb 23 2018 02:34
I eventually want that to pass in a class name and get it off that
what would that look like
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:34
sorry?
Robert
@JaramilloRobert
Feb 23 2018 02:35
No problem
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:35
and don't like of the fbv
with class based views you write less code
Robert
@JaramilloRobert
Feb 23 2018 02:35
man you are being super helpful
do you have a god example
*good
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:37
like this @JaramilloRobert
like this
but good luck man and good job :) it is wrong to learn.
see u bye!
Robert
@JaramilloRobert
Feb 23 2018 02:39
thanks
hey if you havent left yet can u explain where the <int:pk> would get specified
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:40
a pk
Robert
@JaramilloRobert
Feb 23 2018 02:40
i understand pk is primary key
yes
Robert
@JaramilloRobert
Feb 23 2018 02:41
thanks
ill read through that
really appreciate all the help
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:41
you need to pass now a pk on your url
you're welcome man :)
Robert
@JaramilloRobert
Feb 23 2018 02:41
how do i give you credit
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:41
today I help you tomorrow can be you help me :)
Robert
@JaramilloRobert
Feb 23 2018 02:41
sounds like a plan
Leandro Barbosa
@Leeaandrob
Feb 23 2018 02:42
;)
bye
Leo Marlin
@liaodalin19903
Feb 23 2018 02:51
who can help me with this?
Robert
@JaramilloRobert
Feb 23 2018 02:52
you have any idea why there would be an error saying that the urls.py couldn't import the IndexListView
You are above me in this right now man sorry
Robert
@JaramilloRobert
Feb 23 2018 02:58
got it
Robert
@JaramilloRobert
Feb 23 2018 03:33
hey in django is a id created by default for our models
Robert
@JaramilloRobert
Feb 23 2018 04:07
hoping someone can help me out here my web app is not recognizing a part of it as a registered name space
I am pasting the template @ https://dpaste.de/eO0E
I dont get why this is happening and could really use an explination if i take the url piece out that uses 'gradebook:detail' it works fine. Any help would be appreciated
philipmutua
@philipmutua
Feb 23 2018 08:15
Hi guys, how do I multiply values in a queryset?
here is a pice of code I have written
class AdjustmentView(generics.ListCreateAPIView):
    queryset = Adjustment.objects.all()
    serializer_class = AdjustmentSerializer

    def get_adjustment(self):
        Adjustment.objects.filter(employee_month_id=1,adjustment_type=2)
        .values('exchange_rate','amount').aggregate(Sum('amount', total="exchange_rate*amount") )
philipmutua
@philipmutua
Feb 23 2018 09:48
Which is the best way of Optimizing Queries across Foreign Keys in Django applications that has multiple databases ?
emihir0
@emihir0
Feb 23 2018 15:29
@philipmutua you use F to multiply objects in, ie: .aggregate(total=Sum(F('exchange_rate') * F('amount')))
also, queryset are evaluated lazily, only when the actual value is needed, and so you can keep your code easier to read by doing something like:
def get_adjustment(self):
    qs = Adjustment.objects.filter(employee_month_id=1, adjustment_type=2)
    qs = qs.values('exchange_rate', 'total')
    qs = qs.aggregate(total=Sum(F('exchange_rate') * F('amount')))
    return qs