#django

/

      • kezabelle
        don't dump it to JSON? If you want to send/return JSON, it's fine as is.
      • FunkyBob
      • geekodour08 joined the channel
      • geekodour08 has quit
      • PtxDK
        hah it works now :)
      • setre
        not sure I follow :(
      • PtxDK
        Is there a way to specify only the order of fields in the form?
      • kezabelle
        yes. output them in the order you want them :p
      • setre
        kezabelle: do you mean not to use json.dumps? how do I then apply the encoder?
      • kezabelle
        "If you want to send/return JSON, it's fine as is."
      • FunkyBob
        setre: are you starting with a Python object, or a string from somewhere?
      • nedbat
        when i edit a django template in vim, all of the '%}' closing bits are highlighted in red as if they are syntax errors. What's the best Django set up for vim? I've tried https://github.com/vim-scripts/django.vim and https://github.com/tweekmonster/django-plus.vim, and the problem persists
      • setre
        FunkyBob: a list of python objects
      • FunkyBob
        setre: and you want to serialise that to JSON ?
      • setre
        yap
      • daydreamm joined the channel
      • FunkyBob
        json.dumps(the_data_object)
      • does the job quite nicely
      • setre: is this, perhaps, going throug hthe template engine somewhere?
      • how, exactly, are you passing this JSON blob to the calendar widget?
      • setre
        I think maybe although I have valid json the problem may be that fullcalendar.js doesn't accept it as such
      • lemme see
      • I don't think the template engine is involved
      • FunkyBob
        how, exactly, are you passing this JSON blob to the calendar widget?
      • setre
        this is my view:
      • def simple_cal_view(request):
      • context = {}
      • return render(request, 'cal.html', context)
      • amirpro has quit
      • so yeah
      • no wait
      • I use return JsonResponse(data, safe=False)
      • FunkyBob
        ok
      • setre
        and data = json.dumps(list(events), cls=LazyEncoder)
      • hop
        nedbat: i think i use standard html syntax highlighting. all tags are one colour, but oh well
      • FunkyBob
        where did LazyEncoder come from/
      • and how is the browser requesting and parsing this?
      • setre
        the script fullcalendar is requesting it via ajax I guess
      • no complaints in the console
      • nedbat
        hop: if you use filetype=htmldjango, do you get the right coloring for django pieces?
      • lxer
        What would be an easy way to add checkboxes to a table, and then use it for some actions (like in the Admin pages) ?
      • knbk
        setre: you're double-encoding your json. Use json.dumps() or JsonResponse, not both
      • hop
        nedbat: i'm checking right this moment, sec
      • setre
        knbk: ahh thanks
      • ovalseven8
        I get an error having this: https://dpaste.de/8Jy0
      • GinFuyou
        I'm completely lost how translations work under the hood... does this make any sense: https://dpaste.de/qSXN
      • ovalseven8
        Variable annotation cannot be combined with tuple unpacking
      • hop
        nedbat: same thing
      • GinFuyou
        It seems to work if function is defined in models.py, but not on import
      • nedbat
        hop: as me? Red for %} ?
      • amcorreia joined the channel
      • hop
        nedbat: no, sorry, once color for the tags
      • dedsm joined the channel
      • nedbat: ah, the difference is different colors for comments and stuff
      • nedbat
        hop: i think my problem is due to some other html thingy i have installed....
      • knbk
        ovalseven8: you need to create a dict and unpack it: https://dpaste.de/T52E
      • hop
        nedbat: `:scriptnames` and a fine tooth comb...
      • ovalseven8
        knbk, Thank you! Why does it work here, however? https://stackoverflow.com/a/4723261
      • nedbat
        hop: yes, thanks
      • kyern has quit
      • knbk
        ovalseven8: that's not what you were doing
      • kezabelle
        ovalseven8: because you're not giving it a dict of kwargs
      • had you done, .get(**{...}) it'd work
      • ovalseven8
        kezabelle, But this is also not a dict here? https://stackoverflow.com/a/4723261
      • kezabelle
        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.
      • sumiau has quit
      • nedbat
        hop: found it: watch out for https://github.com/luochen1990/rainbow :)
      • baguzzzaji
        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
      • FunkyBob
        ovalseven8: well
      • GraysonBriggs joined the channel
      • sleep time for me
      • asej
        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