Michael, Thanks for the response.
I understand that part but what if i wanted to make it arbitrary. In the
case of an arbitrary variable called "attribute". Something like
user_profile.get(attribute) where attribute can be anything (ie 'firstname',
'lastname').
Is there a way to get a arbitrary attribute from the model?
Michael Newman-4 wrote:
>
>
> It's even easier than that: try user_profile.name
>
> if you need a specific variable field, remember it is just python so:
>>> from Model.models import Profile
>>> user_profile = Profile.objects.get(pk=1)
>>> attribute = 'name'
>>> getattr(user_profile, attribute)
> John
>
> Hope that helps, Mn
>
>
> On Oct 2, 10:47 am, WillF <[EMAIL PROTECTED]> wrote:
>> Hi I'm new to django. Is there way to get a specific column from a
>> specific
>> table in a database when using Models. Say for instance I wanted just a
>> list
>> of user's firstnames or something.
>>
>> Also, with a instance of a Model, say for instance, UserProfile, is there
>> a
>> way to get an arbitrary attribute. Soemthing along the lines of
>>
>> user_profile.get('name') or user_profile.get(attribute)
>>
>> ??
>>
>> Thanks!
>> --
>> View this message in
>> context:http://www.nabble.com/Models---getting-specific-attributes-question-t...
>> Sent from the django-users mailing list archive at Nabble.com.
> >
>
>
--
View this message in context:
http://www.nabble.com/Models---getting-specific-attributes-question-tp19780767p19782299.html
Sent from the django-users mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---