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 ?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top