@classmethod
set_name(cls*, instance*):
prefix = cls.session.query(Prefix.name).filter_by(pk=*instance*.
prefix_fk).scalar()
item = cls.session.query(Item.name).filter_by(pk=*instance*.
prefix_fk).scalar()
suffix = cls.session.query(Suffix.name).filter_by(pk=*instance*.
prefix_fk).scalar()
name = prefix.name + " "+ item.name + " " + suffix.name
instance.name = name
return
I am not entirely sure what the cls does in the function. I thought that
it would let me access the instance of the object, but it does not appear
to do that. The change above, passing the instance of the class to the
function, and doing the queries to the instance work as I expected.
Essentially, I thought cls was "self".
I am still interested if there is a way to automatically call this function
at creation so that if I explicitly pass name="Some Legendary Item with a
cool name", rather than leave it None, it will use the custom name, but
otherwise auto-generate names based on the prefix, item, suffix. I assume
that would just be a custom __init__? (Been using Declarative since that
is what the ORM tutorial shows.)
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.