#django

/

      • cfoch
        I want to make something like
      • <p> field1 :{{ myobject.field1}}</p>
      • <p> field2 :{{ myobject.field2}}</p>
      • ...
      • <p> fieldn :{{ myobject.fieldn}}</p>
      • But I'm really lazy to write all my fields (they're too much fields). Is there a short way?
      • HowardwLo
        ahhhh, does strftime() format not have a non-zero padded day of the month?? http://docs.python.org/2/library/datetime.html#... or am i going blind
      • blubblubb
        cfoch: write a small script to do it for you
      • hoody_k has quit
      • bkeating_ has quit
      • xsamurai joined the channel
      • tbaxter
        cfoch: if you're using a form (and you should), then just output form.as_p
      • cfoch
        tbaxter: it is a model
      • tbaxter
        Even better. Then use a modelform
      • bradfordtoney joined the channel
      • Oh wait. "field" confused me. You're not outputting a form at all. You're trying to dump out all your model attributes.
      • munichlinux has quit
      • No, there is no shortcut, as it's almost always a bad idea.
      • bmac joined the channel
      • cfoch
        tbaxter: what is a bad idea?
      • datakid joined the channel
      • tbaxter
        Although there have been some conversations on here about whipping up a model outputter similar to how modelforms work, in which you would specify safe-to-output fields and then be able to do something like that. But I don't think anyone has been motivated to do anything like that.
      • blindly dumping model attributes
      • Tjati has quit
      • thepeculiarform has quit
      • And even aside from the fact that many attributes shouldn't be dumped, there's the problem of how to format dates, how to dump relationships. It's all a big ball of not-worth-it.
      • cfoch
        is there a way to get the data of the model as a dict? So I can do something like
      • {% for key, value in data.iteritems %} <p>{{ key }}: {{ value }}</p>{% endfor %}
      • my task would be easiest: i think
      • mattmcc
        cfoch: Build the dict that you want in your view.
      • bradfordtoney has quit
      • tbaxter
        cfoch: you're trying to do something that is not a good idea. There is an underlying problem here. Maybe it's that the model has too many fields. Maybe you're trying to output too much, maybe you're not paying attention to HOW things are being output. Without having a better idea of what you're working with, I can't say.
      • mattmcc
        Or write a model method that returns the dict.
      • tbaxter
        Both of mattmcc's suggestions will work. But I still think you're trying to work over another problem.
      • I mean, how many are "too many fields"?
      • adamsilver joined the channel
      • Andy80 has quit
      • Andy80 joined the channel
      • FunkyBob
        tbaxter: I think you want this link :) http://bash.org/?866112
      • cfoch
        about 17
      • tbaxter
      • FunkyBob
        17 fields? that's all?
      • tbaxter
        17 isn't really that many at all
      • And I'm guessing that at least 2 or 3 of them can't be just blindly output, because they require some special handling (dates, FKs, M2M, etc)
      • probably more like 5 or 6
      • cfoch
        and... I had to divide it in 4 forms
      • sorry... 4 models
      • tbaxter
        we're not talking about forms are we?
      • cfoch: maybe you should show us these models.
      • pydonny has quit
      • I mean, are you talking about 17 fields across 4 models? So each model has ~4 fields on average?
      • FunkyBob: yes. that :-)
      • cfoch
        tbaxter: no...
      • do you want to see it???
      • mattmcc
        Yes, seeing is better than guessing.
      • klaut has quit
      • tbaxter
        I am curious what's going on with this model that makes it so difficult, yeah.
      • cfoch
      • username: peterpan
      • password: monosacarido
      • get logged with that
      • tbaxter
        no, I want to see the model(s)
      • cfoch
        ok
      • patrick91 has quit
      • livingstn has quit
      • arphen has quit
      • oubiga has quit
      • dman777 has quit
      • tbaxter: It's Application... before Application, Check, Paypal and BanTransfer where in an only one model called Application
      • livingstn joined the channel
      • oubiga joined the channel
      • FunkyBob
        cfoch: small tip -- don't import models just to use them in relation fields... e.g. Persona
      • instead, use the string form... in this case, user = models.ForeignKey('userprofile.Persona')
      • yofel has quit
      • same for Event
      • it helps to avoid circular imports
      • tbaxter
        OK, model-wise I think you're on the right track. There are a few things I could quibble about, but it's not bad at all. Looking at your model, though, I think you *really* need to take the time to output your details by hand carefully. You have quite a few M2Ms you'll need to output as a list, or FKs that you wont want the unicode() from. I also think you won't want to output a lot of those fields all the time.
      • huntercool has quit
      • watermel0n has quit
      • you need to return a nicely formatted unicode string. You probably want return 'Application {0}'.format(self.id)
      • ehmatthes joined the channel
      • yofel joined the channel
      • brupha has quit
      • Anyways, taking the time to output that stuff carefully now will seem like Too Much Work, but you'll be miles ahead over the long haul.
      • bkeating_ joined the channel
      • bkeating_ has quit
      • FunkyBob
        tbaxter: +1
      • there are some things you just can't provide a generic solution for
      • tbaxter
        Well, you could, but it'd be a lousy solution.
      • FunkyBob
        s/can't/shouldn't/
      • mykul has quit
      • calamari
        can I use secure cookies for django sessions?
      • cfoch
        I'm grateful. thanks...
      • FunkyBob
        calamari: it's in the docs... so, I'd say yes
      • calamari
        FunkyBob: I must be looking at the wrong page then, my apologies
      • cfoch
        I will follow your recommendations
      • calamari
        thanks
      • oubiga has quit
      • mykul joined the channel
      • Ariel_Calzada joined the channel
      • bite joined the channel
      • Katharsis
        I'm using MainPageContent.objects.get_or_create(id=1)[0] which constantly raise exception "matching query does not exist". Can you tell me why?
      • yofel has quit
      • ustunozgur joined the channel
      • dfunckt has quit
      • get_or_create(id=1) should create new object if it doesn't exists - docs said that
      • FunkyBob
        Katharsis: can you dpaste the traceback?
      • Katharsis
        sure
      • ustunozgur has quit
      • yofel joined the channel
      • valgrind has quit
      • FunkyBob
        105. this = MainPageContent.objects.get(pk=self.pk)
      • Katharsis
        MainPageContent is a singleton model
      • FunkyBob
        that's what's raising the exception
      • not a get_or_create
      • Katharsis
        so, self.pk has to be 1
      • ehmatthes has quit
      • FunkyBob
        File "/home/katharsis/workspace/kadastudio/src/config/models.py" in save
      • yeah... I've never liked singleton models
      • mykul has quit
      • kyrobeshay has quit
      • Katharsis
        FunkyBob: http://pastebin.com/Tn6mggn6 part of save method
      • eVRiAL has quit
      • tbaxter
        what's a singleton model?
      • Katharsis
        as you can see, I'm using if self.pk, so object should be created
      • FunkyBob
        Katharsis: right... so when get_or_create is trying to save the one it's creating... your save tries to load it!
      • tbaxter: a model that can only ever have one row in the table
      • tbaxter
        sounds weird
      • FunkyBob
        Katharsis: but get_or_create is setting the pk
      • because you told it to
      • eVRiAL joined the channel
      • Katharsis
        tbaxter: why? it's good for user configuration/settings
      • tbaxter
        never run into one before. Not sure what you'd use one for
      • dfunckt joined the channel
      • FunkyBob
        Katharsis: there are plenty of other tools to provide user configuration besides singleton models
      • tbaxter
        Katharsis: I use settings for settings :-)
      • Katharsis
        tbaxter: not django project settings, I mean user profile settings
      • adamsilver has left the channel
      • tbaxter
        user profile settings are part of the user profile (or have a relationship with it). So that table could have as many rows as there are users.
      • Katharsis
        FunkyBob: so, should I call super(MainPageContent, self).save(*args, **kwargs) first?
      • tbaxter: another example, settings for project (payments) which admin can edit from django admin site
      • tbaxter: imo, singleton is right for this situation
      • CapnKernel has quit
      • gremmie has quit
      • EyePulp joined the channel
      • thepeculiarform joined the channel