On 16 déc, 10:26, JF Simon <[email protected]> wrote:
> thanks dude.
>
> any idea to split the dict on the _ char ?
> recursive function ?
Probably not the most elegant solution, but it should do the trick:
def add_to_context(self, context, field):
current = context
parts = field.name.split('_')
last_part = len(parts) - 1
for part_num, part in enumerate(parts):
if part_num == last_part:
current[part] = getattr(self, field.name)
return
current = current.setdefault(part, dict())
def get_context(self):
context = {}
for field in self._meta.fields:
self.add_to_context(context, field)
return context
HTH
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---