Thanks, Ian,

I appreciate your advice and have removed the first conditional (if name not in duties).

Have now changed that to:

    duty = Duty(date=date)
    duties[date] = duty

    if name not in volunteers:
        volunteer = Volunteer(fore=fore, surn=surn, name=name)
        volunteers[name] = volunteer
        volunteer.duties.append(duty)

which gives me all the volunteers and their correct last date of duty.
How can I include all the previous dates for each volunteer?

Basically, I do not know what to do if the volunteer is already in the dictionary. I presume that I put an else: after the last line of the code snippet but what do I do then? It seems that currently I am overwriting the data as it comes in, so that only the last is shown.

I feel that I am so near and yet so far.

Thanks,

Calum

On 13/01/12 08:15, Ian Kelly wrote:
On Thu, Jan 12, 2012 at 3:14 PM, Calum MacLeod<pan...@sky.com>  wrote:
     if date not in duties:
         duty = Duty(date=date)
     duties[date] = duty

     if name not in volunteers:
         volunteer = Volunteer(fore=fore, surn=surn, name=name)
     volunteers[name] = volunteer
     volunteer.duties.append(duty)
If the date or the volunteer are already in the respective dicts, you
never assign the 'duty' or 'volunteer' variable.  Thus it would retain
its value from the last iteration.  This is probably why you seem to
be missing volunteers -- some of your dict entries are getting
clobbered with the wrong volunteers.

Cheers,
Ian


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to