[Grok-dev] Modeling a class that extend from list() with megrok.rdb

Santiago Videla santiago.videla at gmail.com
Tue Oct 26 08:14:23 EDT 2010

Hi, I am not working with megrok.rdb these days neither with grok... but,
did you see rdb.Container and rdb.QueryContainer? I am not sure, but maybe
it could help you with this.


On Mon, Oct 25, 2010 at 7:02 PM, Hector Blanco <white.lists at gmail.com>wrote:

> Hi list!
> I am trying to migrate my application from ZopeDB to MySql. I am using
> megrok.rdb.
> I have a class which inherits from list() and has a few extra methods.
> That class acts as a container of other classes and is used (as an
> attribute) in other classes as well:
> class MyEntry(object):
>        def __init__(self):
>                self.field1 = “field1”
>                self.field2 = “field2”
> class MyContainer(list):
>        def __init__(self):
>                super(MyContainer,self).__init__()
>        def append(myEntry):
>                if isinstance(myEntry, MyEntry):
>                        super(MyContainer, self).append(myEntry)
>        def getByField1(self, field1):
>                for element in self:
>                        if element.field1 == field1:
>                                return element
>                return None
>        [ ... more useful methods ...]
> class MyClass(object):
>        def __init__(self):
>                self.container1 = MyContainer()
>                self.container2 = MyContainer()
>                self.anotherField = “hello world”
>        def getContainer1():
>                return self.container1
>        def getContainer2():
>                return self.container2
> I don't really know how to model this with megrok.rdb. I kind of see
> clearly (although I may be totally wrong) that MyEntry and MyClass
> should extend from rdb.Model and each of them should be stored in a
> table, but I don't really know what to do with “MyContainer”. I'd like
> to keep it inheriting from list, but I don't know how to model that.
> It really only needs to be an association between [id, id_of_my_entry]
> (relationship 1:N). In MyClass, each of the containers would get an id
> and then, if I want to get the “MyEntries” that are in container1, I
> just need to get the MyEntries who are linked to that id.
> … but I have no idea about how to implement that... Any hint I could
> get would be deeply appreciated.
> Thank you in advance!
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev

Santiago Videla

Sigue la mata dando de que hablar siempre abajo y a la izquierda donde el
pensamiento que se hace corazón resplandece con la palabra sencilla y
humilde que l at s tod at s somos.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20101026/04591273/attachment.html 

More information about the Grok-dev mailing list