[Grok-dev] Multiple models inside container

Lumir Jasiok lumir.jasiok at vsb.cz
Thu Mar 17 08:32:17 EDT 2011


Hi,

right now I have small app with one model, one AddForm as is below:

class Awis(grok.Application, grok.Container):
     def __init__(self):
         super(Awis, self).__init__()
         self.title = "AWIS"
         self.store_id = 0

class IStore(interface.Interface):
     store_id = schema.Int(title=u'Store ID', default=1)
     title = schema.TextLine(title=u'Name', required=True)
     address = schema.Text(title=u'Address')
     storesman = schema.TextLine(title=u'Storesman', required=True)
     description = schema.Text(title=u'Description')

class Store(grok.Model):
     grok.implements(IStore)

class AddStore(grok.AddForm):
     grok.context(Awis)
     form_fields = grok.AutoFields(IStore).omit('store_id')

     @grok.action('Add Store')
     def add(self,**data):
         self.context.store_id = self.context.store_id + 1
         data['store_id'] = self.context.store_id
         store = Store()
         self.applyData(store,**data)
         store.store_id = self.context.store_id
         self.context[str(self.context.store_id)] = store
         self.context._p_changed = True
         self.redirect(self.url(store))

But now I want to add Employee class, that will be similar to Store 
class. Inside Employee AddForm I want to save inside Awis context. After 
that I will not be able to recognize which ID belongs to Store object 
and Which to Employee object. How can I correctly save Store objects and 
Employees objects inside Awis container and be able to recognize them. 
Using dictionaries - self.context.stores and self.context.employees? - 
but how can I access those dictionaries from TAL?

Or am I completely wrong and there is better way to do it?

Best Regards

Lumir

-- 
  Lumír Jasiok
  VSB-TU Ostrava - Computer centre
  Tel: +420 59 732 3189
  E-mail: lumir.jasiok at vsb.cz
  http://www.vsb.cz



More information about the Grok-dev mailing list