Wow. I guess it wasn't such a stupid question. foo._meta.fields .. each field will give me att names but not values. All the methods on the fields that look like they return values only return the values you give them, WTF?
Foo.objects.filter(pk=1).values()[0] requires 2 calls to the database since the object I'm after has methods I actually want to use. I have to get do foo = Foo.objects.filter(pk=1) foo_data = Foo.objects.filter(pk=1).values()[0] Just seems stupid to make two calls to get data I already have. Hmm perhaps I should do foo = Foo.objects.filter(pk=1) foo_form = FooForm(instance=foo) data = foo_form.cleaned_data ok I figured something, it's stupid and couldn't possibly be the "right" way to do it but it does what I need. foo_data = Foo.objects.filter(pk=1).values()[0] foo = Foo(**foo_data) Vance On Mon, Sep 1, 2008 at 12:12 PM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > On Mon, 2008-09-01 at 15:10 -0400, Jay Parlar wrote: >> On Mon, Sep 1, 2008 at 2:48 PM, Vance Dubberly <[EMAIL PROTECTED]> wrote: >> > >> > So I'm finding there are multiple places where I'm needing to iterate >> > over the properties of a Model and I'm absolutely certain it's got to >> > be insanely easy to get a dictionary from a model but for the life of >> > me I can't figure it out, and I can't find any documentation on the >> > matter. >> > >> > basically I want to be able to do this: >> > >> > class Foo(models.Model): >> > bar = model.CharField(max_length=20) >> > barfoo = model.ForeignKey(Bar) >> > >> > foo = Foo.objects.get(pk=1) >> > foo.get_dictionary() >> > {'barfoo': 1, 'bar': 'bar value'} >> >> There might be a better way, but try taking a look at >> foo._meta._fields It does't give you exactly what you need, but the >> pieces are there. > > Even simpler, Foo.objects.filter(pk=1).values()[0]. > > Regards, > Malcolm > > > > > > -- To pretend, I actually do the thing: I have therefore only pretended to pretend. - Jacques Derrida --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---