#django

/

      • FunkyBob
        indeed
      • nonny_t joined the channel
      • ciurkut has quit
      • moveax3 has quit
      • moveax3 joined the channel
      • Leeds joined the channel
      • desophos
        any advice on my question?
      • doismellburning
        desophos: sorry, JS isn't really my thing
      • FunkyBob
        override __init__
      • rtpg joined the channel
      • desophos
        FunkyBob: on what?
      • FunkyBob
        on the form
      • are you trying to do a dynamic cascading select?
      • desophos
        no, not cascading
      • everything stays the same except the form
      • i mean the input fields
      • i just want to populate the fields of the form based on the fields of the model, but i want to be able to do that by selecting a model on the page
      • mattimck_ has quit
      • ranu has left the channel
      • i don't even have a custom form defined
      • FunkyBob
        how can you have a form with no form defined?
      • EyePulp joined the channel
      • if you use a basic ModelForm, as it shows you in the docs you can pass the model as instance= and it will populate it
      • desophos
        sorry, that's what i meant
      • FunkyBob
      • desophos
        a basic ModelForm
      • FunkyBob
        I'm confused about what you are saying and what you are saying you meant
      • cilkay
        FunkyBob: Greetings of the season!
      • hubx has quit
      • jds has quit
      • royendgel has quit
      • Genitrust has quit
      • jaykay has quit
      • desophos
        sorry. i know about instance=; that's what i was planning to use, but how do i get the model that the user chose in order to pass it as instance?
      • FunkyBob
        wait... I think you may need to start this again
      • desophos
        i want to repopulate the form with the model fields every time the user selects a new model
      • FunkyBob
        what do you mean "the model the user chose"?
      • or do you mean the instance of the model?
      • cilkay: hey... how's things ?
      • cilkay
        Making progress on my DRF + AngularJS application. The question above reminds me why I chose AngularJS. :)
      • aron_kexp joined the channel
      • How are things with you?
      • FunkyBob
        cilkay: heh... personally I'm a fan of KO...
      • limbera
      • FunkyBob
        things are ok.. I'm the only one in the office, and am writing extensive and pdenatic tests for a revised API using nap
      • limbera
        i end up with raw strings in my HTML src
      • instead of <label> tags
      • is that normal ?
      • FunkyBob
        limbera: how are you rendering it?
      • limbera
        {{ field.label }}
      • cilkay
        Tests... who needs 'em? :)
      • VinceZa has quit
      • SoftwareMaven has quit
      • FunkyBob
        cilkay: this client... badly
      • limbera
        in a {% for fields in form %}
      • desophos
        FunkyBob: sorry, i'm still not totally clear on the terminology. i mean that there's a <select> dropdown with a list of different customers, and the user chooses one, which corresponds to a DB entry; then, the form text fields should be populated according to that entry's fields. once the form is populated, the user can select another customer from the <select> dropdown, which overwrites the existing form fields with its own data.
      • and i'm not sure of the best way to accomplish that
      • koobs joined the channel
      • FunkyBob
        desophos: ok, so you want to use AJAX to populate your HTML form fields according to the instance selected by a select list
      • desophos
        yes
      • NCS_One has quit
      • FunkyBob
        so you need either: a) a view that returns the instance values as a JSON blob and b) JS to update your form inputs with this data
      • or (a) a view that returns the HTML for the form, and (b) JS to replace your form markup with what's returned
      • royendgel joined the channel
      • desophos
        well, one more thing is that all the values for all the relevant instances are already in the context
      • FunkyBob
        desophos: that's meaningless... you're talking about doing work in the browser... so there is no context any more
      • the template is rendered, the game is over...
      • desophos
        oh, ok
      • in that case, i'm trying to do the former of the two options you mentioned
      • learner joined the channel
      • kunalg_ joined the channel
      • but isn't there another option? i.e. give the view the instance values and have it populate the form using instance=
      • limbera
        FunkyBob: am i not rendering it correctly (regarding form labels)
      • FunkyBob
        limbera: dpaste the actual template
      • limbera
        ok
      • FunkyBob
        desophos: as I said, you could have the view render the HTML for you
      • limbera
      • Nizumzen joined the channel
      • FunkyBob
        limbera: I think you want {{ form.label_tag }}
      • limbera
        gotcha
      • perfect thank you
      • desophos
        FunkyBob: oh right i see, what i just said was what you were referring to with the latter option
      • so then, which is the better choice?
      • kunalg_ is now known as kunalg
      • FunkyBob
        desophos: well, that's the $64,000 question, innit? :)
      • if your app is likely to provide mroe of a RESTful interface to your data, then the JSON approach is probably best
      • kunalg has quit
      • mehola has quit
      • warrenjin has quit
      • desophos
        hmm... unfortunately, the option values aren't enough information to find the correct instance in the DB (not unique identifiers). is it bad to include PKs in the HTML?
      • Derailed
        'Allo. My client has asked for two things to be in an upcoming release: (a) upgrade to django 1.7 (b) include a fix that will require a data migration and a database schema migration. So I'm in the position of working out how to do a switch from south -> django migrations AND some migrations as well. On a scale of one to bad, how bad an idea is this?
      • FunkyBob
        Django's default method of rendering selects is to use the object PK as the option value
      • Derailed: not bad
      • Derailed
        FunkyBob -> you think it's workable?
      • FunkyBob
        Derailed: my path would probably be: (a) make sure all existing deploys are fully migrated, (b) rename migrations/ to south_migrations/ in all apps, (c) create initial migrations for django 1.7, (d) create data/schema migrations in django 1.7
      • Derailed
        FunkyBob, does the rename make them invisible to South, or does south still find them?
      • dray3 joined the channel
      • FunkyBob
        Derailed: South 1.0+ will prefer south_migrations/
      • Derailed
        ^^ looking at docs I see
      • cool, that's a good first step then
      • FunkyBob
      • ras__ joined the channel
      • naro joined the channel
      • chxane has quit
      • Derailed
        Cheers -- I admit I asked before going through the docs in detail (sorry FunkyBob), I'll read through and see what's what.
      • the migration has to delete some stuff from the database and then add a constraint to prevent it happening again
      • I haven't had to do a data migration like that before
      • FunkyBob
        it's simple
      • at least, it is in South :)
      • ras__
        Hi there, had a quick questions on migrations as well. I’m trying to alter my primary key into using a UUID but I get the following error on runing migrate https://gist.github.com/rserna2010/e765ba3aaa48..., here’s my model https://gist.github.com/rserna2010/67ca122e407f... and here’s the migration I’m attempting to run: https://gist.github.com/rserna2010/037bc7d88fca...
      • FunkyBob
        ras__: the nightmare of changing your PK type is you have to also update any other model that has a FK/1to1 to it
      • ras__
        ah this is still in development with no real data to store, do you just suggest deleting the migrations and dropping the table?
      • nonny_t has quit
      • veb joined the channel
      • desophos
        FunkyBob: if i were to go the form-repopulation-route with instance=, how would i re-render just the one form without messing up the other parts that depend on passed context?
      • FunkyBob
        desophos: well, you wouldn't use instance=
      • bibhas has quit
      • unless you were trying to leverage a ModelForm as a cheap API serialiser tool [a valid approach]
      • desophos
        oh, ok; the appeal of instance= for me was that it would automatically handle the fields, giving some degree of future-proofing
      • so i wouldn't have to fiddle with the fields manually every time i change the model
      • FunkyBob
        desophos: I think you're confused about what's going on
      • desophos
        probably
      • FunkyBob
        and how things work
      • desophos
        definitely
      • FunkyBob
        instance= is an option for passing to a ModelForm
      • jarshwah has quit
      • but if you're passing JSON blobs.... typically you don't use the modelform
      • dray3 has quit
      • mliqu has quit
      • desophos
        well, i mean instead of passing a JSON blob (for that i would just return an HttpResponse to an ajax GET request, right?)
      • uhh wait
      • FunkyBob
        mmm?
      • if you don't return a JSON blob, what are you returning?
      • nimomo joined the channel
      • VinceZa joined the channel
      • telex joined the channel
      • desophos
        well, instead of having the view serialize the instance, it would use the instance directly to recreate the ModelForm
      • FunkyBob
        and then what?
      • what will your view return to your JS?
      • desophos
        nothing; the view would re-render the template
      • FunkyBob
        it's sounding increasingly like you have trouble understanding what's client side and what's server side
      • re-render the whole template?
      • ouch
      • I thought you were going with an AJAX solutino
      • to avoid re-rendering the whole page
      • desophos
        right, i was also trying to figure out if there's a way to re-render just the one form
      • ub1quit33 has quit
      • FunkyBob
        yes, and can also be done using AJAX