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

2008-06-13 Thread Wim Feijen
Works like a charm, thank you very much! On Jun 12, 2:09 am, Johannes Dollinger <[EMAIL PROTECTED]> wrote: > You are looking for setattr():http://docs.python.org/lib/built-in- > funcs.html#l2h-66 > > for attr in ('groupon', 'companyon', 'addressfirst', 'extendnames',   > 'clubfieldson'): >      

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

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

2008-06-11 Thread 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:

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

2008-06-10 Thread Russell Keith-Magee
On Tue, Jun 10, 2008 at 9:25 PM, Wim Feijen <[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

Can I loop over attributes in model.attribute?

2008-06-10 Thread Wim Feijen
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! Wim Feijen --- My not-too-pretty code: settings =