#django

/

      • FunkyBob
        modelform
      • why are you touching the modelform?
      • gah
      • mcspud
        I came into this late
      • <tindus> uh, there is no request object in the ModelForm
      • afidegnum joined the channel
      • FunkyBob
        mcspud: no, there's no request on the modelform.... so what?
      • the code I gave you goes on the view
      • where you already have a form_valid method
      • bed666
        mcspud
      • Its a Serializer instance
      • mcspud
        FunkyBob: Yeah, I know, but I think hes confused :) (I came onto this late)
      • bed666
        because I'm passing like this: 'user': UserSerializer(data=user)
      • mcspud
        bed666: great, thats the right way to do it
      • Whats the error now?
      • FunkyBob
        tindus: please excuse my manner... I'm a little tired and stressed from sitting in a hospital all y/day as my son got his appendix out
      • mcspud
        FunkyBob: is he ok?
      • FunkyBob
        mcspud: yep
      • mcspud
        Good stuff
      • how old?
      • bed666
        really? mm look the complete code: https://dpaste.de/pQcm
      • the error is : ValueError: Cannot assign "UserSerializer(data=<User: d>)": "Question.user" must be a "User" instance.
      • tindus
        oh, no problem, FunkyBob
      • your knowledge is worth your curmudgeonliness ;)
      • FunkyBob
        tindus: as I said... rip all that shit out of your form.. and to it in the view's form_valid method
      • tindus
        yes, mcspud, that was my point, that request isn't passed to modelForm. Not in scope, or however you'd describe it
      • FunkyBob
        tindus: not needed in the form...
      • tindus
        well, in another class, I have a required foreign key. I don't want to even show it to the user, so that's the way I figured out to not have the user have to pick himself from a list of users.
      • FunkyBob
        ...
      • "another class" ... ooh... all mysterious
      • mcspud
        bed666: can you post your model code please
      • bed666
        of what
      • question?
      • its very big
      • tindus
        I made a form that doesn't have that item, and I stored the current user as a _user "loose" variable on the form object that is created. (the unbound form?)
      • mcspud
        yeah
      • thats ok
      • tindus
        the thingy class
      • FunkyBob
        tindus: ... again... move your work into the view's form_valid method
      • tindus
        members list all the movies, books, &c they have, and other people in their club(s) can peruse them and ask to borrow them
      • aavrug has quit
      • bed666
      • tindus
        so, a member who adds a thingy doesn't need to select themselves from a pop-down list. The thingy should get created with the current user as the owner
      • ulhas joined the channel
      • Nizumzen joined the channel
      • dray3 joined the channel
      • Paradisee_
        hello o/
      • d3prof3t
        FunkyBob, hi
      • FunkyBob, which is the better approach to go; uWSGI+Nginx or Gunicorn+Nginx ?
      • FunkyBob
        d3prof3t: depends
      • mcspud
        tindus: You said above if a member creates a club, then they should be added to that club right
      • If so, this is pretty much what you want: https://dpaste.de/CRZ3
      • d3prof3t
        FunkyBob, hm, on?
      • Tanger has quit
      • ulhas_ joined the channel
      • dna joined the channel
      • FunkyBob
        mcspud: given tindus has already linked to their class-based view code...
      • mcspud: nad I already gave sample code showing how to do it..
      • mcspud: we can only conclude tindus is ignoring the solution
      • mcspud
        FunkyBob: didn't see that. I just wanted to stop you committing suicide with frustration :)
      • tindus
        yours is superior, FunkyBob
      • ulhas has quit
      • mcspud
        LOL
      • FunkyBob
        mcspud: not really... it just fits with what you already have
      • tindus
        i would love to use form_valid() to do all this kind of stuff
      • mcspud
        FunkyBob: ?
      • jladage joined the channel
      • tindus
        but sometimes, an object has required fields, so how can your form object create a model object with missing stuff?
      • ulhas_ has quit
      • codeme joined the channel
      • in other words, when does a form object become an instantiated model object which MUST have required info?
      • mcspud
        FunkyBob: I think you meant tindus perhaps.
      • ulhas joined the channel
      • tindus
        anyway, I think a form object gets created "unbound", sent via "GET", filled in with info back to django via "POST"...
      • TurBoss joined the channel
      • does it need to have required fields at this point?
      • does what I believe accurately model reality?
      • FunkyBob
        tindus: unbound means it wasn't passed data...
      • your idea of when the objects are created and persists is warped
      • tindus
        lots of my ideas are, but about this:
      • FunkyBob
        GET request comes in, unbound form is created, template is renderd, response is sent to browser. end
      • POST request comes in, bound form is created, validation is checked...
      • tindus
        ModelForm creates a form class, right? but it has no data in it when GET presents it to the user?
      • FunkyBob
        it has no data bound to it when it is not passed data t obe bound to
      • in a CreateView, it does not pass data to bind in a GET request....
      • don't conflate these two things
      • mcspud
        tindus - When you "return" the HTML response in a GET request, the "unbound form" is destroyed/garbage collected
      • tindus
        let me read what you have so far, and digest.
      • FunkyBob
        remember, you're dealing with two HTTP requests... the GET and the POST
      • both are wholely independant
      • tindus
        so, bound form != valid data
      • FunkyBob
        correct... bound form simply means it was passed data
      • it could be invalid data
      • mcspud
        there are two different things entirely
      • tindus
        bound form just means you can't edit the data in the extant form object?
      • FunkyBob
        this is all covered in the form docs
      • no, it does not mean that
      • tindus
        i read those docs, and they are not pedantic enough
      • FunkyBob
      • mcspud
        jebus
      • This one is tough work
      • grumpi has quit
      • FunkyBob
        this is one of the reasons I think it's better people learn to write views well before they're exposed to CBGV
      • mcspud
        yeah
      • tindus
        I agree
      • I think
      • ;)
      • you mean I should dick with function=based stuff until my understanding increases?
      • FunkyBob
      • in the end, all views are functions
      • Poulet has quit
      • tindus
        oh, it's bound to a http action OR to data?
      • dna has quit
      • mcspud
        tindus: This may help you understand: https://dpaste.de/yovT
      • x3al_ joined the channel
      • Otherwise I'm giving up
      • Paradisee_
        is there a way to let only superuser see a page?
      • codeme has quit
      • mcspud
        A modelform becomes "bound" when it relates exactly to a model instance
      • sagaragarwal94 has quit
      • So in the example I posted, it checks the database, if it can't find an existing model it creates one, and it returns a "bound" form, which means that it is displaying data
      • FunkyBob
        tindus: to data
      • mcspud
        Now, if it creates a model, there might be a whole bunch of default data that gets created with it
      • codeme joined the channel
      • tindus
        why is it "insurance, created = ... "
      • i though that was how you assign two variables, but you gotta have two on the right
      • mcspud
        The get_or_create method returns:
      • the new/existing model instance, and a boolean letting you know if it was created or not
      • mitaka has quit
      • codeme has quit
      • Paradisee_
        anybody read my question?
      • tindus
        ok, docs.django v1.8 can't find AbstractRegistrationView
      • I really did try to rtfm this time.
      • mcspud
        tindus - thats my custom view class
      • ignore it
      • Ignore everything I wrote, its confusing you.
      • Do what FunkyBob said and go and write simple function based views
      • When you understand that, then dip your toes into CBV
      • jladage has quit
      • kingplusplus has quit
      • ASonOfGod joined the channel
      • eka
        Paradisee_: maybe permission_required decorator on the view?
      • tindus
      • Paradisee_
        eka: gonna check.
      • tindus
        has mention of a similar method in queryset
      • thanks, guys. I have gotten actual work done with your help.
      • eka
        Paradisee_: or you can use is_staff to build your own decorator
      • tindus
        red turned to green. Refactor is next
      • jcda joined the channel
      • timkofu joined the channel