Google app engine db model static ( class ) variables
-
03-07-2021 - |
Domanda
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
?
Soluzione
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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow