I'm stumped...

Setup: (Problem statement near the bottom)

In my Pylons app, I have three separate models: Customer, TPPAnswer,
SAQ
TPPAnswer is many-to-one Customer
SAQ is many-to-one Customer

Both have backreferences (so saq.customer and customer.saqs)

Currently, I have them defined in customer.py, tpp.py, saq.py.
Additionally, I have common.py which is where the metadata object
comes from -- all three import everything from common.py

In order to have the TPPAnswer many-to-one Customer reference, I
import customer_table and Customer so that I can do (w/i tpp.py):
from customer import customer_table, Customer
...
mapper(Answer, answers_t, properties={
    'customer'  :relation(Customer, backref='tpp_answers'),
})

I have a similar setup for saq.py.


-----------------
Problem:
in customer.py in the Customer class, I need to reference .tpp_answers
and .saqs... but because those references are created in tpp.py and
saq.py, they are not known to the Customer class.

If I have already imported the tpp model (in my controller), then the
Customer object is aware of self.tpp_answers but not
self.questionnaires:
  self.questionnaires
AttributeError: 'Customer' object has no attribute 'questionnaires'

If I have already imported the saq model, then the Customer object is
aware of self.questionnaires but not self.tpp_answers.

I can't import both saq and tpp in the controller:
  self._pre_existing_column = table._columns.get(self.key)
AttributeError: 'Column' object has no attribute '_columns'

How do I set up my model such that I can import the pieces I need when
I need them?  So if I call a certain method of the customer object
(adjust_grade() for example) it will be able to acquire all the
attributes it needs.  I don't want to have a massive file with all the
relations in them, because most of the time I only need a part of
them.  For instance, a lot of the things I do with the SAQ model never
even interact with the customer -- same with the TPP model.  It's the
occasional interaction amongst all three of them that's giving me
grief.

Sorry for such a wordy, confusing explanation.  I'm glad to clarify if
it helps.
-----------------

class Customer(object):

    def adjust_grade(self, *whatchanged):
        self.tpp_answers
        self.questionnaires
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to