pass the arg to your view via the urlpattern, then pass it on to the template
tga
and sometimes /companies/1/department/2/equipment/3/edit
with a company layout, a department layout, and a detail layout
each expecting the object in context
so in this case all views under /companies/ need to retrieve a company by company_pk, and all views under /department/ need to retrieve the company and department
flobin
so I'm trying to write my first class based views and I'm getting an error I don't really understand... what am I doing wrong here? https://gist.github.com/Flobin/99bb92ad12a5b51a... (views, urls, models, and template are also on that page)
tga
helper function? base class? decorator?
flobin: your categories url pattern is commented out
flobin
but should that even matter if I'm not trying to access that url?
Coldblackice joined the channel
tga
flobin: you are trying to resolve an url that doesn't exist (because it's commented)
flobin
but how am I trying to resolve it, I mean?
nikojn joined the channel
this_is_tom has quit
tga
flobin: anything relevant in base.html?
you don't have that one in here
flobin
ohh
vmenezes has quit
there is {% block categories %} {% endblock categories %} for which there is a template
moldy: alright, so you're saying independent views, thanks
and I guess context processor for things like /COUNTRY/foo app-wide
fractalized
robomedia: try to use “annotate” instead, as described in docs
robomedia
ok thx I will play with it
ironfroggy joined the channel
vinny3 joined the channel
space-wizard joined the channel
tga
hmm, context processors get access to the request, but not to url params?
that's kind of a problem, if I have a global url param like <country>, all views must either take a country param or **kwars
**kwargs rather
I don't expect a context processor could remove that param somehow?
hmm middleware, right?
ironfroggy_ joined the channel
maryokhin has quit
abrookins joined the channel
ok so my current question is: urls are like /COUNTRY/all_other_views -- based on COUNTRY, I want to get an object from the database and put it in request (then I'll put it in context with a processor)
is this middleware?
robomedia has quit
mekhami
in my template i have something like {{ if title.publisher }}{{title.publisher}}{% endif %} and then a similar line on the next line
is there a way to remove that newline if one or the other is false
so i don't end up with blank lines
tga
I don't think you should care that much about white space in generated html
unless it causes actual problems
Knyght
sometimes it causes actual problems though
mekhami
it's not html
it's something else
i'm using the template engine to write business files too
and it probably doesn't matter either in the files i'm sending but
Knyght
mekhami: I can't think of much beyond sticking it all in a template tag but if you have other things with the same behaviour that could get awkward pretty fast
mekhami
it might bother my business partners' needs
i thought about doing it all on the same line and putting newline characters inside the {% if %} statements
but that's a real ugly template
ah wait
this is a neat little trick
tga
I guess what you'd really need is new lines inside template tags
mekhami
let me show you
lorddaedra joined the channel
tga
because you are actually adding a new line that the template has to honour
the django template language is pretty braindead and will only take you so far
(by design)
lotek0816 has quit
flobin
if I have a URL like this: url(r'category/(?P<pk>\d+)', CategoryView.as_view(), name='category'), how do I get the pk into the class based view so I can filter the queryset with it?
I tried queryset = Article.objects.filter(categories=pk)
but I get NameError: name 'pk' is not defined
javawolfpack_ joined the channel
Jon_R
self.kwargs['pk'] i think
abrookins has quit
flobin
I now get NameError: name 'self' is not defined
javawolfpack has quit
javawolfpack_ is now known as javawolfpack
Jon_R
ok you need to learn python first before trying django :-p
my project contains a function that was copy-pasted from a django core function (as I required part of it I couldnt properly monkeypatch).. how does that work in terms of licensing?
maryokhin joined the channel
does that mean I need to include the BSD license and copyright notice?
Jon_R
how big was the thing you copied?
tga
in theory I think the answer is yes, if you copy any BSD code you have to include the license