Pergunta

In GAP you you create a model, they show it by :

 class Pet(db.Model):
        name = db.StringProperty(required=True)
        type = db.StringProperty(required=True)
        birthdate = db.DateProperty()
        weight_in_pounds = db.IntegerProperty()
        spayed_or_neutered = db.BooleanProperty()

Why are this created as static variables?

Shouldn't they be but in the __init__() method and cleard as self.variable ?

Foi útil?

Solução

When you instantiate an instance of Pet, it's not instantiated traditionally, they're created with a metaclass.

Read up here on what a metaclass is: What is a metaclass in Python?

There's a section in there labelled "Why the hell would you use metaclasses?", which discusses the Django ORM briefly. The db.Model scheme is fairly similar to the Django ORM, so that explanation applies.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top