Python - Accessing subclasses' variables from parent class while calling classmethods
Question: i'm trying to build sort of a "mini django model" for working with Django and
MongoDB without using the norel Django's dist (i don't need ORM access for
these...).

So, what i'm trying to do is to mimic the standart behavior or
"implementation" of default models of django... that's what i've got so far:

File "models.py" (the base)

    
    
    from django.conf import settings
    import pymongo
    
    class Model(object):
        @classmethod
        def db(cls):
            db = pymongo.Connection(settings.MONGODB_CONF['host'], settings.MONGODB_CONF['port'])
    
        @classmethod
        class objects(object):
            @classmethod
            def all(cls):
                db = Model.db() #Not using yet... not even sure if that's the best way to do it
                print Model.collection
    

File "mongomodels.py" (the implementation)

    
    
    from mongodb import models
    
    class ModelTest1(models.Model):
        database = 'mymongodb'
        collection = 'mymongocollection1'
    
    class ModelTest2(models.Model):
        database = 'mymongodb'
        collection = 'mymongocollection2'
    

File "views.py" (the view)

    
    
    from mongomodels import ModelTest1, ModelTest2
    
    print ModelTest1.objects.all() #Should print 'mymongocollection1'
    print ModelTest2.objects.all() #Should print 'mymongocollection2'
    

The problem is that it's not accessing the variables from ModelTest1, but from
the original Model... what's wrong??


Answer: You must give `objects` some sort of link to class that contains it.
Currently, you are just hard-coding it to use `Model()`s atttributes. Because
you are not instantiating these classes, you will either have to use either a
decorator or a metaclass to create the `object` class for you in each subclass
of `Model()`.

