#django

/

      • FunkyBob
        it's always morning, somewhere
      • [just... not here]
      • fandikurnia01 joined the channel
      • enough foreplay, quantik ... what's the question ? :)
      • logix812 joined the channel
      • quantik
        I have a modelForm and there is some of the fields that are foreign keys to other models. I wanted to override the default widget (input text instead of select) so that the user can provide a new value for these keys
      • FunkyBob
        ok
      • quantik
        When the form is saved, I need to have some logic in my view to check if the key provided already exists. If not, I create it, and if yes well, everything is fine.
      • FunkyBob
        well, the fields should do a lot of that for you anyway
      • quantik
        In order to validate my user inputs, I created additional forms for each foreign keys.
      • FunkyBob
        however... get-or-create on keys? ouch
      • quantik
        yeah...
      • That's bad ?
      • The usage is for a typeahead, does that make sense to you ?
      • Basically I want to populate it with the keys that already exists, but let the user add new ones.
      • PKKid2
      • quantik
        ok that's cool.
      • mykul joined the channel
      • m1yag1 joined the channel
      • It will shorten some of my code. I have a follow-up question however.
      • If i use get_or_create, it wont validate the inputs right?
      • mykul has quit
      • mattmcc
        Right.
      • PKKid2
        quantik, You can do that after you run is_valid() on your form.
      • Frostig joined the channel
      • FunkyBob
        PKKid2: tsk tsk... giving out dev doc links...
      • quantik
        Ok. I have another question then
      • flebel has quit
      • FunkyBob
        well, I'm off to lunch...
      • PKKid2
        FunkyBob, :P
      • quantik
        What if my form does not validate, Is there a way to bind the errors for this particular form to the one of my modelForm ?
      • rideh has quit
      • Basically if it fails, I dont want my form to display an error related to the fact that the foreign key is non existant, but insteand, have one saying why the foreign( which is a charField with custom validators) did not validate.
      • sadris
        FunkyBob, thanks for your help, I got it figured out
      • keimlink has quit
      • Frostig has quit
      • foxx has quit
      • cewing has quit
      • Titanomachy joined the channel
      • gremmie has quit
      • nlh has quit
      • schweens has quit
      • ojh has quit
      • garnertb has quit
      • sbbrtn has quit
      • donspaulding joined the channel
      • ennajelari
        quantik, i hate form handling in django.
      • i struggled a lot to have a intermediate save option on model forms into the database, and ofcourse managing predefined templates provided by django form/formset
      • nlh joined the channel
      • mattmcc
        quantik: You're completely in control of the validation messages.
      • ojh joined the channel
      • ennajelari: Tools like crispy forms and formulation make rendering much more flexible.
      • sadris has quit
      • FunkyBob
        ennajelari: you're under no obligation to use django Form's rendering ability...
      • mattmcc
        The shortcut output (Just using {{ form }}) really isn't meant to be customized, it's just a quick, basic structure for convenience. If it doesn't work for you, you're much better off just rendering individual fields where you want them, or using a helper app.
      • FunkyBob
        mattmcc: aww.. thanks :)
      • ennajelari
        mattmcc, let met check that :). but i had a issue today that, i could not control "This field required" into the place where i wanted into the template.
      • mattmcc
        Placement, or the wording?
      • ennajelari
        placement
      • webscrapper1
        hey funkybob i need help with some URL mapping
      • mattmcc
        You just need to put {{ field.errors }} where you want it. (Or loop over it, since it's a list)
      • moneydouble joined the channel
      • endra joined the channel
      • webscrapper1
        im getting this error
      • The current URL, rango/category//add_pages/, didn't match any of these.
      • mattmcc
        webscrapper1: It's not lying. That path didn't match any of your urlpatterns.
      • webscrapper1
        i know
      • PoliticsII
        Try it without the double slash.
      • ennajelari
        mattmc, true, that means to avoid default placement of errors, i need to iterate manually all the fields in the form to be displayed in the form. Once i do that, i get all the fields which i donot want to display also.
      • FunkyBob
        mattmcc: placement :)
      • webscrapper1
        heres my url path the problem is
      • urlpatterns = patterns('',
      • url(r'^$', views.index, name='index'),
      • url(r'^about', views.about, name='about'),
      • url(r'^category/(?P<category_name_url>\w+)/$', views.category, name='category'),
      • url(r'^add_category/$', views.add_category, name='add_category'),
      • url(r'^category/(?P<category_name_url>\w+)/add_pages/$', views.add_pages, name='add_pages'),)
      • mattmcc
        ennajelari: Fields that you don't want to display should've been excluded in the first place.
      • FunkyBob
        webscrapper1: don't paste in here!
      • webscrapper1
        sorry
      • ennajelari
        and the fields which i dont want, i kept in the hidden field, and then the field is not posted as part of the request.POST.
      • webscrapper1
        woops
      • mattmcc
        ennajelari: Because just not displaying them doesn't prevent their values from being changed by the user. If they shouldn't be changed, they shouldn't be in the form.
      • webscrapper1
      • adrian_lc has quit
      • the category_name_url
      • i dont know how to get that recognized
      • it works for the other page
      • FunkyBob
        where did the url come from? the one that's failing
      • djnumpy13 joined the channel
      • ennajelari
        mattmcc, what i am doing is i am creating the dynamic form in the UI through ajax, once you click add more button lets say, i create a backend model instance for the same.
      • PoliticsII
        webscrapper1, \w+ looks for at least one \w
      • moneydouble
        Anyone know of a good django store/shop/ecommerce app/project? open source
      • Nelluk
        man i cant believe how much easier writing an ORM Model is in django than in symfony
      • kbambz joined the channel
      • moneydouble
        Nelluk: I came from PHP, I used the Kohana framework over symfony, I now hate PHP. lol :P
      • ennajelari
        and keeping the primary key of newly created instance into the form, so that i can use it to update the fields provided by user which is invalid
      • webscrapper1
        umm im supposed to pass the category to the page views
      • kbambz has quit
      • moneydouble
        Django + Python = Awesome. <3
      • webscrapper1
        so the url is in that structure
      • Nelluk
        havent heard of kohana myself
      • ennajelari
        mattmcc, intention is to keep saving the form what the user enters, and once saved, then while user submits, i need to do validation.
      • k_sze[work]
        So there was a mention here that QuerySet union with ManyToManyFields can produce a wrong count: http://stackoverflow.com/questions/4411049/how-...
      • kbambz joined the channel
      • webscrapper1
      • mattmcc
        ennajelari: Well, I don't know how much I can help with your particular use case, I was just pointing out that if you're avoiding iterating over the form's fields because it has things you don't want, you're doing what we call "fighting your tools"
      • webscrapper1
        im working on the exercises there
      • k_sze[work]
        Anybody knows if this is a reported issue on the Trac?
      • mattmcc
        Iterating over the fields is a really easy way to handle custom form rendering, it's not something you should want to avoid.
      • Hipikat
        wow i only just encountered the way django templates fail to iterate on defaultdicts because lookup precedence. that was annoying.
      • k_sze[work]
        I tried searching with the 'queryset union' keywords, but none of the results seem related.
      • ennajelari
        mattmcc, getting the point :). Do you have any suggession to implement partial form saving?
      • mattmcc
        But more importantly, having fields in your form that aren't displayed is not going to prevent their values from being changed by a user who knows the names of those fields.
      • rideh joined the channel
      • k_sze[work]: The ORM can't do unions.
      • Nelluk
        moneydouble: havent looked at ecommerce django packges til now. kinda want to play with one, thanks a lot ;)
      • FunkyBob
        Hipikat: explicitly call keys?
      • mattmcc
        k_sze[work]: It can combine criteria, but that's not the same thing.
      • Nelluk
        since our ecomm site is on.. umm. cough.. classic asp
      • moneydouble
        Nelluk: haha, nice.
      • basti-mbp joined the channel
      • FunkyBob: did you make a store app? seems like I recall you saying you had one.
      • Hipikat
        FunkyBob: keys unknown. just casting to dict() before passing to template… :)
      • FunkyBob
        moneydouble: am currently working on a rather large store...
      • k_sze[work]
        mattmcc: 'combine criteria' as in combining the 'WHERE' clause?
      • knite has quit
      • mattmcc
        k_sze[work]: Yeah.
      • moneydouble
        FunkyBob: open-source?
      • FunkyBob
        nope
      • moneydouble
        ah
      • FunkyBob
        I've done some simple stores at times...
      • Nelluk
        oscar commerce looks pretty nice
      • k_sze[work]
        mattmcc: then I wonder how that bug was at all possible in the first place.
      • mattmcc
        k_sze[work]: Well, if the combined criteria results in different joins (e.g, outer joins instead of inner) than what you were expecting, it would effect the results.
      • basti-mbp has quit
      • rideh has quit
      • eka has quit
      • andym joined the channel
      • hwrd|work joined the channel
      • airtonix
        does this seem like a sensible way to do postgres master / slave replication ? https://www.digitalocean.com/community/articles...
      • i'm looking to add some ansible plays that setup postgres master/slave repliction. I've never done it before though.
      • FunkyBob
        airtonix: how does it compare to what's in the actual Postgres docs?
      • airtonix
        Nelluk: oscar is very nice. very similar to django-shop but more sensible and mature
      • dray3 has quit
      • ustunozgur joined the channel
      • Nelluk
        ive been playing with it and reading its docs for a few minutes. only negative i can see is that it has some dependencies that arent that actively developed, so who knows if it'll ever be py3 compatible
      • airtonix
        FunkyBob: I wouldn't know, since I've not read the postgres docs to find that. I don't imagine there would be some conten there that is along the lines of "Best practice setup of master / slave replication"
      • Nelluk: i doubt it will be for a while. but then isn't that true of most django apps?