#django

/

      • django_noob
        I see "qpe.is_valid()"
      • jtiai
        Page just cutted out the rest nicely in my browser.
      • geekodour08 joined the channel
      • But yes, form, serializer both are very close to each other and do work.
      • django_noob
        what is the difference between APIView and viewsets?
      • jtiai
        They're different tools.
      • apiview is very primitive.
      • zothix
        what are the cons of using " return HttpResponseRedirect(request.META.get('HTTP_REFERER')) "
      • JustASlacker has quit
      • jtiai
        viewsets otoh are very highlevel tool that handles basic CRUD for you.
      • And creates "standard" url endpoints as well.
      • But since your usecase is just to get single value you don't need post/put/delete actions.
      • django_noob
        ah okay so you are saying i dont need the tooling of viewset
      • tyrion-mx
        django_noob, I think you would find very useful reading the "API Guide" if you haven't already (there are sections for views and viewsets :)
      • django_noob
        I guess what confuses me is this answer here
      • iamriel has quit
      • jtiai
        And please, don't read SO. It's so full of pure crap.
      • django_noob
        The accepted answer aruges that the router doesnt work with general views
      • Haudegen joined the channel
      • jessamynsmith
        there are good answers on SO, as well, but it can be difficult to tell the good from the bad
      • tyrion-mx
        django_noob, that seems to be correct, if you're using a normal view you want to register it normally, like you would for a django view
      • jessamynsmith
        that is true, django_noob
      • if you want an apiview, you put it in urls like a normal view
      • django_noob
        oh okay
      • jessamynsmith
        what tyrion-mx said :)
      • django_noob
        well
      • thanks so mcuh for the help
      • normally i can get things done
      • but i get hung up on "best practices"
      • last question
      • whats the difference between using django rest router and normal django url patterns?
      • jessamynsmith
        they are completely different
      • url patterns hook a single view to a single endpoint
      • tyrion-mx
        to understand that you have to understand the difference between viewsets and views. And then you can understand what a router is :)
      • jessamynsmith
        the router is used to hook a viewset to the router, which generates a set of url endpoints
      • django_noob
        ahhhhhh
      • ok
      • ok
      • i got you guys
      • jessamynsmith
        if you were hooking up CRUD in url patterns, you would need at least 4 patterns
      • that is just one router/viewset hookup
      • django_noob
        and router would help for that
      • tyrion-mx
        to understand all this, my suggestion would be to go through the tutorial (it has all that covered)
      • django_noob
        im not a fan of the tutorial
      • tyrion-mx
        why not?
      • django_noob
        My biggest grudge is that it focuses on model view sets and model serializers
      • and I have this unique situation where I have a view that is using multiple models
      • jtiai
        Well that's to most common usage.
      • jessamynsmith
        django_noob: it's not terribly unique, and there are many ways to handle it
      • tyrion-mx
        django_noob, it's an overview of the whole framework, you can skip the parts that are not interesting :P
      • django_noob
        fair enough
      • jessamynsmith
        django_noob: have you read through this? http://www.django-rest-framework.org/api-guide/...
      • If the models are not related, I question why they are in one api endpoint
      • django_noob
        outside the context of django, does a endpoint need to accommodate both post and get to be considered "restful"
      • They are related
      • I am using all of them to compute a value
      • and this endpoint returns that value
      • frans has quit
      • jtiai
        django_noob: That is very normal and there is no magic involved.
      • You can even use standard Django function based view to do that.
      • jessamynsmith
        sorry if I am repeating what others already said, but that sounds like an apiview since you don't need crud on it, you just need a single view
      • tyrion-mx
        django_noob, don't worry about "restful" :)
      • django_noob
        can a non apiview that does have all crud operations still be considered restful?
      • jtiai
        django_noob: restulf is an architecture style.
      • tyrion-mx
        django_noob, "rest" and restful are abused words that mean very little. If you want to understand what REST is, you could read roy fielding's dissertation
      • but that would take up some time
      • jtiai
        REST in practice from O'Reilly is also pretty good book.
      • astarrh joined the channel
      • derk0pf joined the channel
      • tyrion-mx
      • masterrex
        This is only a 1/2 django question... give an entity that would have a status (occupied/available) tied to a time frame (either start datetime + duration or startime/endtime), how would you query whether a device is available given a certain point in time?
      • I don't know if I'm tripping myself up by thinking about time as a continuum rather than thinking pragmatically - but I'm curious what kind of answers I'll get!
      • oxygene joined the channel
      • django_noob
        Thank you to everyone that helped me design my api endpoint
      • newdimension
        I have one template file that I want to use for different models. Anything wrong with defining get_delete_url() and get_edit_url() at the model level similar to get_absolute_url()?
      • firefox1337
        call a query at a certain time and get the result?
      • django_noob
        really really appreciate
      • gonna run with apiview
      • Alphare has quit
      • foxmask has quit
      • django_noob has quit
      • astarrh has quit
      • astarrh joined the channel
      • stahl has quit
      • jessamynsmith
        masterrex: I would use start and end and then query based on current time
      • JordiGH has left the channel
      • knbk
        masterrex: on postgres you can use DateTimeRangeField, which comes with some convenient lookups as well
      • jaddison has quit
      • ironi
        anyone here familiar with the FieldTracker from django-model-utils?
      • totallyserious joined the channel
      • totallyserious
        let say I have a table, Offers, but I want to make one of them special and have references to it programmatically
      • what is the best way to go about doing this?
      • ironi
        I want to calculate and update some fields when a model is updated, so I'm adding a pre save signal - I need the exsiting db datas to be able to do the calculations, is there any better way to do this than just do a get?
      • idontneedanick has quit
      • jakogut_ has quit
      • masterrex has quit
      • jakogut joined the channel
      • masterrex joined the channel
      • ptx0 joined the channel
      • firefox1337 is now known as firefox
      • jaddison joined the channel
      • VikingHoarder has quit
      • masterrex has quit
      • jaddison
        totallyserious you mean mark a given Offer instance as 'special'? A boolean field or some choices-based field. What do you mean by refer to it programatically? a ForeignKey field?
      • amirpro has quit
      • whatever_hi joined the channel
      • ironi doing a get in pre_save works, but you can also override the model's `__init__(...)` to copy the relevant data to a tmp instance variable for comparison in a pre_save signal (or overridden .save(...))
      • ironi
        is instance._state.adding safe to use in a signal to check if a model instance is being updated
      • jaddison
        At least, I think that would work
      • ironi
        I have a model with a uuid pk so cant do if self.pk\
      • jtiai
        ironi: Why not?
      • ironi
        jaddison: interesting
      • jtiai: being a private property and I can't find it in the docs
      • jtiai
        ironi: pk property should be documented somewhere...
      • amirpro joined the channel
      • beebot_ joined the channel
      • ironi
        jtiai: oh you mean why not, because the uuid field has uuid.uuid4 as default and those are set before saving
      • jtiai
      • ironi
        jtiai: I could of course set it in a custom save method
      • or maybe there is a better way I'm not aware of
      • jtiai
        I think in pre_save default values are not yet applied.
      • (django docs are not explicit about when default values are applied in object save sequence)
      • beebot_ has left the channel
      • ironi
        jtiai: ah right,
      • you might be right
      • ASUchander
        I'm trying to use Djangos RequestFactory to make requests to my django code without using the http server.
      • However, when I do a get(), I get back a WSGIRequest object - how do I go from there to a HttpResponse?
      • jtiai
        ASUchander: Please see the topic.
      • n000b has quit
      • ironi
        jtiai: it's actually already set there
      • jtiai
        wonder was there creating or similar kwarg passed in pre_save...
      • bradfordli123 joined the channel
      • bummer, no there isnt. :/
      • mrhanky has quit
      • mrhanky joined the channel
      • masaki joined the channel
      • Meteorite has quit
      • safwan joined the channel
      • astarrh has quit
      • enoq has quit
      • zeus1 joined the channel
      • astarrh joined the channel
      • lolidunno joined the channel
      • astarrh has quit
      • astarrh joined the channel
      • masaki joined the channel
      • Guddu joined the channel
      • lavalamp joined the channel
      • nix64bit has quit