#django

/

      • lavalamp has quit
      • sunil_bansal has quit
      • pangolin_ joined the channel
      • morenoh149
        do django form properly provide a datetime widget when the model field is DateTimeField?
      • mattmcc
        No, that's up to you.
      • morenoh149
        docs say `Default widget: DateTimeInput`
      • is that on the admin ui?
      • looks like I can provide input_formats to it, but then I need to explicitly define the form in form.py no? and I can't use the fields variable in the view anymore
      • rpkilby joined the channel
      • mmm, no that arg already has a default value
      • so I'm meant to supply a full datetime string to the form from the UI? no way to attempt html inputs from the django side?
      • html5
      • Leeds joined the channel
      • rpkilby has quit
      • Oli has quit
      • mattmcc
        If you want the html5 date picker, you can customize how the widget is rendered, or subclass it to make your own.
      • Adding on a JS date picker is usually pretty easy too.
      • morenoh149
        I'm just using a string for now, the browser keeps previous inputs in history
      • Oli joined the channel
      • event-detail is a named path in urls.py I can even navigate to it just fine event/3
      • GraysonBriggs joined the channel
      • this is after submitting the event form
      • GraysonBriggs has quit
      • kingarmadillo has quit
      • kingarmadillo joined the channel
      • tubaman has quit
      • darkhanb has quit
      • jamessharpe joined the channel
      • shangxiao joined the channel
      • Donitzo has quit
      • converge
        Im using form.as_p option, how could I add/control the css/classes of each retrieved field form ModelForam
      • *ModelForm
      • amcorreia
        N
      • morenoh149
        converge: you override it with converge https://docs.djangoproject.com/en/2.0/topics/fo...
      • disregard the first part of the message
      • gah, fixed my issue, needed to do 'polls:event-detail' as I'm using url namespacing
      • audioburn has quit
      • Venomen joined the channel
      • Venomen has quit
      • lacrymology joined the channel
      • Lambertini joined the channel
      • converge
        morenoh149, thanks !
      • rpkilby joined the channel
      • xcm has quit
      • FunkyBob
      • xcm joined the channel
      • Lambertini has quit
      • morenoh149
        does form_valid enforce csrf?
      • rpkilby has quit
      • jamessharpe has quit
      • FunkyBob
        no
      • csrf is handled in middleware
      • xcm has quit
      • morenoh149
        I'm writing a phone app, should I query a page to get the csrf token?
      • jamessharpe joined the channel
      • FunkyBob
        yes
      • I generally do that on my "login check" url... so you make it do, say, GET /auth/ and check if it's logged in
      • xcm joined the channel
      • that ALSO has @ensure_csrf_token on it
      • then if youre not logged on, you POST /auth/ or whatever
      • kill two birds with one stone
      • hop
        don't kill birds. birds are nice people
      • FunkyBob throws stones at hop
      • you can kill me. i'm not good people
      • morenoh149
        thanks, sounds like I need to tackle auth next
      • hop
        is the app the only client?
      • audioburn joined the channel
      • totallyserious joined the channel
      • totallyserious
        Hey if I have revisions of an object at different times, anyway to efficiently find out the value of an attribute at a given time X?
      • FunkyBob
        depends on how you're storing revisions
      • totallyserious
        I am using django-reversions so I can retrieve them from a list
      • hop
        totallyserious: how do you it now?
      • morenoh149 has quit
      • totallyserious
        i iterate through all the reversions and then find out the latest reversion before a given datetime
      • but it's seriously slowly my application
      • hop
        that's not a list, that's a query set
      • but no matter
      • k0mpa joined the channel
      • you should be able to filter by time, no?
      • totallyserious
        yes
      • hop
        wo why do you have to iterate?
      • totallyserious
        is there a name for this type of data retrieval? I believe there should be tools out there that solves this for me
      • hop
        believe harder, maybe something will materialize ;)
      • s/wo/so/
      • nobodi has quit
      • jamessharpe joined the channel
      • well?
      • totallyserious
        EDIT: I am iterating through all the objects and retrieving the data in O(1)
      • but it's still a slow process because of the multiple db calls
      • FunkyBob
        why multiple?
      • hop
        totallyserious: again... why are you iterating, if you can retrieve a revision by date?
      • totallyserious
        let me clear up the confusion
      • schinckel
        You can do more complex queries using reversion.
      • totallyserious
        I misspoke when I said I have to iterate
      • I meant for each object I query the latest revision and access the attribute. I hvae to do this for all instances of that object
      • hop
        so use get_for_model?
      • schinckel
        You can do it all in one query - but it's not necessarily trivial (because it uses generic relations)
      • eb0t
        hey i am createing a job model for job specs. ..within this model i will hae the name of hte client who gave me the spec...and also things like skills, salary etc.
      • totallyserious
        schinckel: can you elaborate on this?
      • eb0t
        the thing is when i display the job form for internal staff...not only do i want the client name, i want the client address , tel, email
      • but they are part of another model
      • in django ...i know i will need to define the client name as a foreign key on my job model
      • but will i also need to define the client telephone number email address etc within my job model ?
      • goldfish joined the channel
      • Info-Screen has quit
      • as they are already defined on the client model
      • hop
        eb0t: by that logic everything would end up in one table
      • eb0t
        and not sure if i need to define them again in the job model aslo as foreign keys
      • hop
        eb0t: ideally you don't duplicate _any_ data in your models
      • eb0t
        hop: are you saying that when displaying the form.....to be rendered for job spec....that i pull data inot the form from several models
      • hop
        eb0t: are you maybe talking about model forms? those are two different things
      • Info-Screen joined the channel
      • eb0t
        hmmm...not sure i know that model forms base their fields on an existing model
      • but im happy to construct a form that bases its fields on multiple models
      • or is that bad news
      • schinckel
        totallyserious: You can use prefetch_related('object') on a reversion.Version queryset. That will possibly be part of it - but that works on going from Version object to the other object.
      • hop
        eb0t: no it's not bad news. why should it be?
      • schinckel
        But that may not be that useful for you - if you have versions all of the same type, you may be able to do a prefetch_related on that...
      • eb0t
        erm ..i really dont know
      • hop
        eb0t: there's also inline forms, but maybe stick to plain forms until you get the hang of it
      • eb0t: don't assume the worst, just because you don't know ;)
      • take_flight joined the channel
      • eb0t
        yes i think i will...thanks ...ill try and knock something together and see if i can get it working
      • hop
        it's just code. trying never hurts
      • eb0t
        yes ...its a bit daunting but has to be sorted one way or another
      • you were saying earlier that ideally you dont need to duplicate any data in your models
      • but isnt using a foreign key a kind of duplication
      • schinckel
        No, it's a reference.
      • hop
        eh? how so?
      • dg_vrani joined the channel
      • schinckel
        (or, a relationship)
      • eb0t
        ah so do you in the model lets say for the job spec....i will need a foregin key to the client that gave it to me ..
      • but when i render the form ....i can just get the other info from the client record
      • so i dont need to put the telephone number and email of the client into the job record
      • s/record/model
      • schinckel
        totallyserious: I have a snippet here to get all Versions for a queryset, but I'm not sure it can be done as a prefetch_related.
      • hop
        eb0t: do you really want to be able to change the client data in a job form?
      • schinckel
        totallyserious: You might be able to do a prefetch if you create a reverse relation on the target object though.
      • eb0t
        no ..but the job must be linked to that particular client
      • hop
        eb0t: i mean, you're basically correct, but from a ui standpoint it sounds a bit iffy
      • eb0t: there are also choice fields, etc.
      • eb0t
        yes i have read a little about that field ...but there may be lots of clients so i dont really want to go that route
      • i mean potentially hundreds
      • leetrout has quit
      • hop
        eb0t: you can go hog wild with autocompletion ajax foo
      • eb0t: but i don't see how _not_ using a choice field would make it easier to choose a client
      • eb0t
        when the staff member puts in a job ...they enter the business name and the contact
      • and lots more information