#django

/

      • g_kub joined the channel
      • scruz joined the channel
      • g_kub has quit
      • Leeds joined the channel
      • azulakina has quit
      • jpg joined the channel
      • kiloreux has quit
      • azulakina joined the channel
      • briian joined the channel
      • briian
        hey, in the templating language, is there a way to do a one line block w/o doing it with an open and close block?
      • the way i dont want to do it is `{% block title %} SomeTitle {% endblock %}
      • nix64bit has quit
      • asej
        can anyone help with class based views and how to deal with form validation correctly when you have two forms on a template, so far I have https://dpaste.de/pvtD
      • lxer joined the channel
      • lxer
        o/
      • tbp has quit
      • tbp joined the channel
      • aossama joined the channel
      • Haudegen has quit
      • moldy_ is now known as moldy
      • frans joined the channel
      • kiloreux joined the channel
      • LordVan joined the channel
      • tbp has quit
      • tbp joined the channel
      • Ergo has quit
      • GinFuyou
        briian, I don't think so... can't just use a variable?
      • briian
        GinFuyou: i can use a variable, but thats not what im asking
      • tbp has quit
      • you mean put a variable in the base template?
      • tbp joined the channel
      • Ergo joined the channel
      • GinFuyou
        yes, with |default if needed. For what you asked I told above: if it's not in docs you most likely can't
      • asimon joined the channel
      • I'm not quite sure if it make sense actually, surely I don't mind shorter syntax but I'm not sure it would be actually contribute to readability
      • pwrentch joined the channel
      • asej, I don't think your PeoductDisplay is a good idea
      • briian
        it might not because of how the {% system works in django
      • in blade (php) itd be @section('section_name') @endsection, or @section('section_name', 'some value')
      • which was nice for titles and stuff
      • GinFuyou
        It's how programming works: some approaches have own pros and cons
      • amirpro joined the channel
      • asej, for your post() part, have you looked at http://ccbv.co.uk/projects/Django/2.0/django.vi... ?
      • basically you just need to fill in with POST two forms
      • You can hack it in together quickly, or go deeper and build customized 2-forms view\mixin with special methods
      • LordVan has quit
      • briian
        thanks im enlightened now
      • GinFuyou
        Generally I advice against messing with concrete view's get() and post() methods, if you don't have a very good reason to (there are such reasons, but not hat common)
      • kezabelle joined the channel
      • briian, C.O. always at your service =^_^=
      • briian
        where do global project modules get stored? i have a script that is gonna be used by multiple apps
      • kezabelle
        hmmm. who's responsible for doing 'date-string'::timestamp in queries, the ORM or the underlying psycopg2 lark, doe sanyone know?
      • briian
        should i just create a modules folder in /modules/
      • s/in/as
      • tbp has quit
      • tbp joined the channel
      • silverbaq joined the channel
      • lxer
        yes, just somewhere in your project folder.
      • viejafea has quit
      • fpghost84 has quit
      • setre joined the channel
      • setre
        hi, how can I serialize a list of objects Foo.objects.all() to JSON but for example modify one of the fieldnames so that e.g. "created_at" becomes "start"?
      • csotelo_ joined the channel
      • tbp has quit
      • linovia
      • tbp joined the channel
      • setre
        do I need the rest framework to do it then?
      • linovia
        oh sorry
      • I though I was on the django rest framework channel. You should be able to do without it
      • setre
        no problem. I can't find it on the googles though
      • GinFuyou
        there is a number of ways to do it, model objects are not serializable on their own anyway
      • kezabelle
        json.dumps(tuple(Foo.objects.annotate(start=F('created_at')).values('fields', 'i', 'want', 'start')) probably, assuming the other fields are normally serializable by json.
      • (nb: totally untested :p))
      • setre
        kezabelle: interesting, thanks
      • GinFuyou
        yeah, was thinking something like that too
      • lxer
        foo_json = serializers.serialize("json", Foo.objects.all())
      • kezabelle
        that doesn't do renaming though (which is the point). And I dunno wtf it does if you throw a .values() at it.
      • zeus1 has quit
      • azulakina has quit
      • setre
        okay how about transforming the data in Foo created_at from datetime to date before serializing it?
      • I mean a 2nd problem
      • scruz has quit
      • linovia
        json.dump would do though you'd probably want to add an encoder/decoder for datetimes
      • setre
        ah thanks
      • dedsm has quit
      • kezabelle
        at the point where you start transforming things though ... use something properly, like rest-framework, or marshmallow, or nap, or serpy
      • lxer
        don't try to do it all at once. just make your query, modify the result, then send it as json (JsonResponse)
      • setre
        great, thanks
      • zivl joined the channel
      • frans_ joined the channel
      • shangxiao has quit
      • frans_ has left the channel
      • azulakina joined the channel
      • idontneedanick joined the channel
      • PtxDK
        in a template, is it possible to both use {{ form.as_p }} and in the same form also define other intries? i ofcourse want to grab stuff from the field in my view but simply calling https://dpaste.de/ihkO#L8,9 does not put email into db with user; note that the user is created but without email
      • kezabelle
        forms only know about the fields they declare
      • so if your form doesn't *declare* an email field, it'll just be summarily ignored by the form and the cleaning (ie: it won't be in cleaned_data, even if it was in data)
      • rns_ joined the channel
      • PtxDK
        hmm
      • this is my template: https://dpaste.de/jaKL
      • kezabelle
        what would be the point in having cleaned data if it just accepted any old thing? :)
      • PtxDK
        but i get what you say, so my thing will not work
      • kezabelle
        your template is wholly irrelevant
      • PtxDK
        well
      • yeah
      • kezabelle
        you can submit a field called "flibbity" if you want. If the form doesn't expect it, it won't care about it
      • PtxDK
        but my problem is that the Form is declared within the django-framework itself
      • kezabelle
        so? subclass it
      • PtxDK
        subclass i dot know about
      • dont*
      • lxer
        you've defined the extra fields in UserCreationForm ?
      • PtxDK
        nop
      • i dont know where or how to do that
      • how do i "extend" the default user form?
      • lxer
        well, you include the file
      • FunkyBob
        same way you extended Models
      • tbp has quit
      • kezabelle
        if you've ever *used* a model, or a form, or the modeladmins and especially if you've written one yourself, you've subclassed
      • subclasses are *everywhere*
      • rns has quit
      • lxer
        ah, you mean you use some Forms from some package (probably allauth or similar), right?
      • kezabelle
        (see also, class based views, etc)
      • tbp joined the channel
      • PtxDK
        i know how to use normal forms and models, but i dont know exactly how to extend things
      • lxer
        MyForm(UserCreationForm)
      • GinFuyou
        You just don't realize you know )
      • PtxDK
        so i import the django-framwork form into my forms.py right?
      • and then do lxer's thing
      • i think i get how it works
      • but when you say "subclass" its like another word for "extending" right?
      • hop
        we usually don't invent "other words" just for the fun of it
      • kezabelle
        it's the same thing, possibly more correct given the different ways extension could happen.
      • hop
        "extending" is more of a concept, "subclassing" a technique
      • kezabelle
        if you like, it's also specialisation through inheritance :o)
      • IcyPalm joined the channel
      • PtxDK
        i just havent really realised subclassing before i guess :3
      • setre
        I am trying to get events into fullcalendar from django and it accepts the first line and creates the event but not the second line for some reason http://dpaste.com/28KZEKA
      • djent has quit
      • if I manually create json (1st line) it loads okay but the output from json.dumps() doesn't work although it is valid json
      • kezabelle
        it's not valid JSON. it's a string.
      • setre
        okay thanks
      • IcusDicus joined the channel
      • Haudegen joined the channel
      • kezabelle
        (well, technically that could also be valid JSON, when parsed via JSON.parse or json.loads() if the string were flat, but that's not the point at hand)
      • derk0pf has quit
      • setre
        this is what made it: http://dpaste.com/3VJBETH
      • how can I make it not be a string?
      • FunkyBob
      • JSON _is_ a string
      • geekodour08 has quit