Re: Can I loop over attributes in model.attribute?

2008-06-11 Thread Johannes Dollinger

You are looking for setattr(): http://docs.python.org/lib/built-in- 
funcs.html#l2h-66

for attr in ('groupon', 'companyon', 'addressfirst', 'extendnames',  
'clubfieldson'):
 setattr(settings, attr, attr in data)


Am 12.06.2008 um 00:48 schrieb Wim Feijen:

>
> Thanks Russell!
>
> I suppose the code I want to get looks like:
>
> settings = Settings.objects.get(owner=userid)
> for switchable in ['groupon', 'companyon', 'addressfirst',
> 'extendnames', 'clubfieldson']:
> if switchable in data:
> settings._meta.get_field(switchable). = True
> else:
>settings._meta.get_field(switchable). = False
>
> My remaining question is, as you may have understood, what text do I
> use instead of  ?
>
> I imagine I could have been using a python function to list some
> options, but I was unable to find out how. I apologize for being
> stupid.
>
> Yours sincerely,
>
> Wim
>
> PS Another thing is, _meta is apparently a hidden function I am not
> supposed to be using. Do you recommend filing this conversation as a
> bug/feature request? Because I would be delighted when we could
> address object columns as settings['groupson'] = False, in order to
> open up all kinds of possible interactions.
>
>
> On Jun 10, 3:38 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> wrote:
>> On Tue, Jun 10, 2008 at 9:25 PM,WimFeijen<[EMAIL PROTECTED]> wrote:
>>
>>> Coding happily away...
>>
>>> And wondering, can I write better code, using a loop, perhaps? In
>>> other words: can I set settings.groupon while using a variable in
>>> stead of groupon?
>>
>>> Thanks for any recommendations you are willing to make!
>>
>> Looks like you might want to have a look at the contents of
>> Settings._meta, also called the Options object. This object  
>> contains a
>> lot of meta-data about the class, such as the various names that can
>> be used to refer to the class, the fields on the class, and so on.  
>> The
>> meta object is available on the class and on instances.
>>
>> In particular, you're probably looking to iterate over
>> settings._meta.fields; each member of this list will be a Field
>> object, from which you can get field.name, field.attname, and many
>> other useful details.
>>
>> Yours,
>> Russ Magee %-)
> >



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: order_by foreign key problem

2008-05-29 Thread Johannes Dollinger

Wah, nevermind ..

Am 30.05.2008 um 01:27 schrieb Johannes Dollinger:

>
>> Should this work??
>>
>>   results = Gear.objects.select_related().order_by 
>> (generic_info__hits)
>
> Quotes are missing:
>
> Gear.objects.select_related().order_by('generic_info__hits')
>
>
>
>
>
> >



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: order_by foreign key problem

2008-05-29 Thread Johannes Dollinger

> Should this work??
>
>   results = Gear.objects.select_related().order_by(generic_info__hits)

Quotes are missing:

Gear.objects.select_related().order_by('generic_info__hits')





--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Use variables inside an 'include' tag (and/or: how to set a variable in a template)

2008-05-29 Thread Johannes Dollinger

You could use a filter:

@register.filter(name='concat')
def concat(value, arg):
return "%s%s" % (value, arg)

and then {% include dir|concat:"/tag.html" %}.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---