문제

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