#django

/

      • cmpahar has quit
      • amites has quit
      • pyjacker joined the channel
      • jsfan2 joined the channel
      • pyjacker
        Is Model.clean and Model.full_clean called on save?
      • domino14 joined the channel
      • the_rat joined the channel
      • Bryson has quit
      • In fact, why isn't Model.clean called on save?
      • arlekin joined the channel
      • domino14 has quit
      • the_rat has quit
      • arlekin
        hi there, sorry to ask this here, but #restframework looks pretty dead right now - in django-rest-framework is there any option for having somewhat polymorphic serializer ? I mean sometimes i want to serialize more fields than i want to deserialize, and it is pain to deal with additional fields in serializer and stuff. Is there any pattern for that ? Maybe i should just have more than one serializer per model ? although that doesn't
      • seem like very good, DRY approach
      • dang`r`us
        hm. how about inheritance?
      • class BasicSerializer, class FancySerializer(BasicSerializer)
      • arlekin
        dang`r`us: that is actually something i didn't think of....
      • pyjacker
        arlekin: so you want to read only a few feilds but display more?
      • eka has quit
      • arlekin
        pyjacker: i have serializer for model, and i would like to use it for both when i pass whole object from form, and when i only retrieve say pk and name for displaying in select field for instance
      • TheJoey
        You can also set fields to read_only, not sure if that's exactly what you're looking for
      • pyjacker
        write_only and hidden are kwargs for serializer fields in django rest framework.
      • rami has quit
      • arlekin: write only seems like what you're after..
      • arlekin
        pyjacker: do i understand correctly that field set to write_only would be applied only when deserializing incoming stuff ?
      • surfnturf joined the channel
      • pyjacker
        As in it being only writable, yes.
      • surfnturf
        whats the easiest way to create an initial data fixture?
      • arlekin
        great, that - and the inheritance approach - should cover all my needs
      • thank you very much dang`r`us, pyjacker, TheJoey
      • arlekin has quit
      • grant116 has quit
      • pyjacker
        surfnturf: use the admin, then dumpdata.
      • surfnturf
        pyjacker: thx
      • transit has quit
      • dray3 joined the channel
      • amikrop joined the channel
      • amikrop
        I want to have the same form for editing and creating objects. Should I use a single django.forms.Form for those?
      • eka joined the channel
      • SecondForm_Glenn has quit
      • Some button names will be different between the 2 cases, and "edit" form will have the values prepopulated
      • Can I use the same django form for those 2 cases?
      • FunkyBob
        the submit buttons aren't part of the Form anyway
      • stantonk joined the channel
      • I thought the tutorial covered using the same form for create/edit
      • I'm quite sure the docs do
      • amikrop
        Oh, really? could find it
      • couldn't*
      • david5aa joined the channel
      • the tutorial doesn't use django.forms
      • delizin
        FunkyBob: iirc the django tutorial covers creating an html form for submitting votes, but never touches django forms or modelforms
      • amikrop
        thanks
      • amikrop has quit
      • Genitrust has quit
      • thinkt4nk joined the channel
      • dray3 has quit
      • Volund
        okay now I need to figure out how Django does GROUP BY...
      • looks like aggregation is the deal.
      • delizin
      • FunkyBob
        aggregate and annotate
      • thinkt4nk has quit
      • transit joined the channel
      • deeprave joined the channel
      • ybathia has quit
      • Volund
        soo... this, maybe.
      • participants = self.poses.exclude(ignore=True).values('owner').annotate(total=models.Count('owner'))
      • basically looking for SELECT owner,count(poses) from poses where ignore=False GROUP BY owner
      • rami joined the channel
      • err
      • count of something
      • pyjacker
        Why is model level validation discouraged?
      • thinkt4nk joined the channel
      • Volund
        actually
      • Volund does this more simply
      • a_little_birdie has quit
      • ASonOfGod joined the channel
      • graffix has quit
      • ojii|work joined the channel
      • psicom joined the channel
      • FunkyBob
        whee... another nap release, now with even more docs!
      • isthisreallife has quit
      • zerok has quit
      • deeprave
        cool, FunkyBob
      • FunkyBob
        MarkusH: if you're alive... I've made datamapper fields a little less tedious :)
      • tw1sted has quit
      • Fuyou has quit
      • uczekalla has quit
      • ollie joined the channel
      • uczekalla joined the channel
      • jladage has quit
      • Muchoz has quit
      • untitaker joined the channel
      • untitaker has quit
      • zerok joined the channel
      • jaddison has quit
      • untitaker joined the channel
      • untitaker has quit
      • cereal
        so i'm assuming there's no way to dynamically add fiends to a model since _meta.fields is an ImmutableList (django class)...wondering if anyone has messed arouond with that idea
      • FunkyBob
        cereal: are you also dynamically fucking with your DB schema?
      • cereal
        naw
      • just adding fields dynamically
      • FunkyBob
        so...
      • cereal
        but not effing with the db
      • FunkyBob
        why?
      • cereal
        because i need to
      • FunkyBob
        ...
      • don't be a twat... explain the problem so we can help you
      • cereal
        right now i'm just adding them as variables to the class
      • I've tossed the idea around a few times
      • but essentially i'm working on allowing dynaimc fields for differnet models of my app
      • aka, tennant a wants to track some random data but tennant b has zero need for that particular data
      • and so forth
      • FunkyBob
        sounds like what django-hstore's "schema" option can do
      • adds virtual fields
      • amikrop joined the channel
      • amikrop
        What is the default max_length of models.CharField?
      • i.e. what does None indicate
      • cereal
        yeah, I messed with hstore but filtering isn't there for anything other than exact string matches
      • FunkyBob
        there isn't one
      • cereal
        i mean, it works don't get me wrong
      • FunkyBob
        amikrop: IIRc you must specify a length
      • agentOrange has quit
      • cereal: well, where are these values to be saved if you're not modifying the schema?
      • amikrop
        FunkyBob: https://docs.djangoproject.com/en/1.8/ref/model... seems to say max_length=None
      • revpj has quit
      • FunkyBob
        amikrop: yes, and it has a check on it that says you must define one
      • but hey, you can keep arguing with me if you like...
      • cereal
        FunkyBob, i'd catch them during a save and handle them that way
      • amikrop
        ok, but why would I argue?
      • just asked
      • cereal
        right now i'm doing custom forms for this and its working
      • just exploring if there's a better way
      • amikrop has quit
      • FunkyBob
        amigo: as I said... you MUST specify a value
      • cereal
        i got distracted by looking at a fields concrete method, and so forth
      • but that might not be the best option
      • pydave6367 has quit
      • ojii|work
        cereal dynamic fields sounds very problematic, maybe what you want is a "key-value" model that links to the original model if hstore doesn't solve your use case?
      • cereal
        i'm currently just having different models for each data-type right now
      • i'm just trying to make it a little cleaner when using it
      • pyjacker
        Anyone more experienced than me care for a SO question?
      • cereal
        its working pretty well, and yea its certainly going to be a bit more intensive than your normal model but sometimes thats just a need
      • FunkyBob
        pyjacker: did you try asking in #restframework ?
      • pyjacker
        Yes.
      • domino14 joined the channel
      • I think the question has relevance for both channels.
      • FunkyBob
        I find the question interesting, because I recently added automatic calling of model-validatin into nap