Pregunta

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 ?

¿Fue útil?

Solución

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 bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top