adam schrieb:
> u = DBSession.query(User).filter_by(user_name=session.get
> ('old_username', None)).one()
> u.user_name = str(kw['username'])
> u.display_name = str(cgi.escape(kw['display']))
> u.email_address = str(cgi.escape(kw['email']))
> u.groups[0].group_id = str(cgi.escape(kw['group']))
> but it throws the error IntegrityError: (IntegrityError) PRIMARY KEY
> must be unique u'UPDATE tg_group SET group_id=? WHERE
> tg_group.group_id = ?' ['3', 5]. What have i missed?
You're trying to change the primary key of an existing group. That's
probably not what you want.
The clean way would be to get the Group instance belonging to
kw['group'] (thereby also checking whether it exists), and appending it
to u.groups (optionally removing an already existing group item).
Also, as already mentioned, you don't need cgi.escape if you use the
validate decorator. Validation will also convert strings to integers
(group_id is an integer, but you're assigning it a string).
-- Christoph
--
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=.