forked from vsergeyev/ndbadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
66 lines (53 loc) · 1.92 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# This is sample models
# Note Meta() class inside model - it is define form fields for CRUD
# and templates for list/new/edit/delete operations.
# Default templates located inside /templates/admin/
# To subclass template: create a folder inside /templates/admin/
# with model name lowercase.
from google.appengine.ext import ndb
from admin import fields
class Item(ndb.Model):
"""
Sample item model
"""
name = ndb.StringProperty()
description = ndb.TextProperty()
image = ndb.BlobProperty()
def __unicode__(self):
return self.name
def __str__(self):
return self.__unicode__()
# this is where Admin CRUD form lives
class Meta():
def __init__(self):
self.fields = [
fields.TextField("name", "Name", required=True),
fields.BigTextField("description", "Description"),
fields.FileField("image", "Image")
]
self.order_by = Item.name
class Order(ndb.Model):
"""
More complex mdoel
"""
item = ndb.KeyProperty(Item)
is_payed = ndb.BooleanProperty()
date_added = ndb.DateProperty()
customer = ndb.StringProperty()
memo = ndb.TextProperty()
price = ndb.FloatProperty()
def __unicode__(self):
return "%s ordered %s" % (self.customer, self.item.get())
def __str__(self):
return self.__unicode__()
class Meta():
def __init__(self):
self.fields = [
fields.KeyField("item", "Item", required=True,
query=Item.query()),
fields.DateField("date_added", "Date", required=True),
fields.CheckboxField("is_payed", "Payed"),
fields.TextField("customer", "Customer", required=True),
fields.BigTextField("memo", "Memo"),
fields.FloatField("price", "Price")
]