what you gave it doesn't even resolve to args I don't think, hence your exception
baguzzzaji joined the channel
no, it's a list of keyword arguments
("kwargs")
baguzzzaji
Hello everyone. I have a field in my model using CharField with choices. When I want to print the field I got ('U', 'Draft'). How to print only the draft?
In django template.
kezabelle
.get_<fieldname>_display
ovalseven8
kezabelle, You mean my bug is that it's returning a string?
maryo joined the channel
knbk
ovalseven8: .get(is_active=False) would work fine, but you can't do the same when the keyword is a variable. `'is_active': False` is syntax you'd use in a dict literal, which is exactly what I showed in the new code
baguzzzaji
kezabelle: I already try get_status_display but it still print the whole tupple.
nazarewk has quit
GinFuyou
baguzzzaji, you doing something wrong then
kezabelle
then I suspect you've saved that into the database?
GinFuyou
forgot to save, reload or that ^
baguzzzaji
I use ModelForm to save the data.
kezabelle
or your choices is malformed, maybe?
open a repl/shell, fetch the object from the db, and call .get_status_display() on the instance. And then dpaste that + models
baguzzzaji
This is the line in my model: status = models.CharField(max_length=1, choices=STATUS, default=STATUS[0])
briian
hop: how are you on this fine friday
zeus1 joined the channel
ovalseven8
knbk, So the packing and unpacking using a dict is actually a workaround to be able to resolve variables?
knbk
ovalseven8: yes
GinFuyou
baguzzzaji, looks wrong
kezabelle
your default should be STATUS[0][0] I suspect
so yeah, I think it's wrong, and you've possibly persisted the whole tuple as a string to the DB at worst.
kezabelle: It should be STATUS[0][0]. I've tried it and its working. Thank you.
kezabelle
np
hop
nedbat: rainbow is that nested-parens thing, right?
nedbat
hop: yes.
hop
nedbat: always gave me visions ;)
baguzzzaji
Another question. If I have Chapters with foreign key to a Novel. Is there a way to count how many chapters a Novel have directly with django query method?
fission6 joined the channel
deepy joined the channel
jeanba joined the channel
briian
wouldnt .count() do that?
lxer
all().count()
kezabelle
^ that, unless you want to do it en-masse, which would be Novel.objects.annotate(chapter_count=Count('chapter')) or some variation thereof I think.
baguzzzaji
lxer: not from view but from template.
fission6
if i have a CSV download thats going to take awhile whats a good archectual approach
FunkyBob
fission6: you're generating the CSV in Django?
frans has quit
fission6
ya, again open to many approaches
baguzzzaji
So, I run Novel.objects.all(). I want to print how many chapters a novel have directly in the template inside forloop.
lxer
baguzzzaji: not sure but I think that would also work , but without '()'
FunkyBob
fission6: well, as a generator it can be quite efficient... but the stdlib CSV module isn't very generator friendly
kezabelle
it would.
greg_f joined the channel
fission6: define "a while"?
fission6
2 minutes
FunkyBob
fission6: oh.... background worker queue
kezabelle
if its a "short while" then streaminghttpresponse + generators would do it (with a bit of legwork), otherwise, farm it off to a queue and check for a result
fission6
OK
thanks! where woud you "hold" the csv
could a simple model work with filefield and status
ovalseven8
My user consists of email + password. Also, users have to confirm their email address to activate the account. Do you think it makes sense to also let them write their password in the "email-activation-view"? I fear that some email providers etc. could automatically check every link in an email and so activate the account (for example because of spam detection)?
kezabelle
depends how big it is.
ovalseven8
What's your experience/recommendation?
kezabelle
if its small but expensive to calculate? meh just send back the string as the result :p
GinFuyou: Can you explain why the ProductDisplay is not a good idea and help with an example of a better way, I am new to django so please bear with me?
zivl has quit
enoq joined the channel
fission6
any thumbs up for using flower or something similar to monitor celery
jezdez joined the channel
kuter has quit
GinFuyou
asej, my bear and balalaika is always with those ready to listen ^_~*
nkuttler
fission6: it's alright
GinFuyou
basically I don't think you need it. You now has 3 views and it can be achieved with 2 or even 1 I believe. depends on exact case ofc
fission6
is it worth having at all
nkuttler
nkuttler
simple to install, has a decent interface
fission6
ok so pretty harmless
just a "nice" to have
GinFuyou
e.g. there no problem usin UpdateView as a DetailView, they both deal with single object
nkuttler
yup. we have built our custom logging system, simply to have everything unified
fission6
we are switching queing services so thought it would be helpful to. have in place just to sanity check workers and such
frans_ joined the channel
nkuttler swapping from rabbitmq to redis in production should be pretty painless? not sure if you have experience with such concepts
GinFuyou
asej, as for posting 2 forms, I suggest you go over methods show in url I gave and write analogy code but for form1, form2