ผลต่างระหว่างรุ่นของ "Quick Start for Developers"
(สร้างหน้าด้วย "Start here == Header 2 == === Header 3 === ==== Header 4 ====") |
|||
| บรรทัดที่ 1: | บรรทัดที่ 1: | ||
Start here | Start here | ||
== | == สร้าง Table == | ||
สร้างหน้าที่แต่ส่วนของ table โดยมีรูปร่างหน้าตาดังนี้<p> | |||
<รูปหน้าที่มีแต่ตาราง> | |||
โดยไฟล์ที่จำเป็นมีดังนี้ | |||
=== Model.py === | |||
กำหนดรูปแบบของ database | |||
<syntaxhighlight lang="python" line="1"> | |||
class Anime(CuneiModel): | |||
id = AutoIncrementField() | |||
stid = IntegerField() | |||
code = CharField(default="") | |||
name = CharField(default="") | |||
type = CharField(default="") | |||
Publisher = CharField(default="") | |||
writer = CharField(default="", null=True) | |||
class Meta: | |||
database = SqliteExtDatabase(None) | |||
</syntaxhighlight> | |||
==== ฟังก์ชั่นการใช้งานและชนิดช้อมูล ==== | |||
*คำสั่งในการใช้งาน | |||
** '''{{code|lang=python|'AutoIncrementField()'}}''': กำหนดให้มีรันตัวเลขอัตโนมัติ | |||
** '''{{code|lang=python|'null'}}''': กำหนดให้databaseสามารถเว้นว่างได้ | |||
** '''{{code|lang=python|'SqliteExtDatabase'}}''': เปิดdatabase | |||
*กำหนดชนิดของข้อมูล | |||
** '''{{code|lang=python|'IntegerField()'}}''': ตัวแปรชนิดตัวเลขที่เป็นจำนวนเต็ม | |||
** '''{{code|lang=python|'FloatField()'}}''': ตัวแปรชนิดตัวเลขที่จุดทศนิยม | |||
** '''{{code|lang=python|'CharField()'}}''': ตัวแปรชนิดที่เป็นตัวอักษร | |||
** '''{{code|lang=python|'TextField()'}}''': ตัวแปรชนิดที่เป็นตัวอักษรและช่องข้อความขยายได้ | |||
** '''{{code|lang=python|'DateField()'}}''': ? | |||
=== Table.py === | |||
<syntaxhighlight lang="python" line="1"> | |||
class Anime_table(CunriTble): | |||
MASTER_colsizes = [1,3,10,10,0,7,7,7] | |||
MASTER_colnames = ["stid", "code", "name", "type", "publisher_stid", "publisher_code", "publisher_name", "writer"] | |||
MASTER_coltypes = ["int", "str", "str", "sel", "int", "str", "str", "str"] | |||
MASTER_choicecols = ["type"] | |||
MASTER_choices = [[("Comedy", "Comedy"), ("Action", "Action"), ("Fiction", "Fiction"), ("Fantasy", "Fantasy"), ("Adventure", "Adventure")]] | |||
MASTER_schfill = {"publisher_code":["ModalPublisher:code", "publisher_stid:stid,publisher_name:name"]} | |||
=== Header | class SubForm(FlaskForm, CuneiSubForm): | ||
stid = StringField("") | |||
code = StringField("", validators=[InputRequired("Required!")]) | |||
name = StringField("", validators=[InputRequired("Required!")]) | |||
type = SelectField("") | |||
# publisher = StringField("") | |||
publisher_stid = StringField("Publisher StID", validators=[InputRequired(lazy_gettext("Required!"))], render_kw={"readonly":""}) | |||
publisher_code = StringField("Publisher Code", validators=[InputRequired(lazy_gettext("Required!"))]) | |||
publisher_name = StringField("Publisher Name", render_kw={"readonly":""}) | |||
writer = StringField("", validators=[InputRequired("Required!")]) | |||
def validate_writer(self, writer): | |||
if len(writer.data) <= 1: | |||
raise ValidationError(lazy_gettext("Very short")) | |||
</syntaxhighlight> | |||
==== Header 4 ==== | |||
==== | == สร้าง Form - non Database == | ||
== สร้าง Form - Database == | |||
รุ่นแก้ไขเมื่อ 11:39, 24 กุมภาพันธ์ 2568
Start here
สร้าง Table
สร้างหน้าที่แต่ส่วนของ table โดยมีรูปร่างหน้าตาดังนี้
<รูปหน้าที่มีแต่ตาราง> โดยไฟล์ที่จำเป็นมีดังนี้
Model.py
กำหนดรูปแบบของ database
class Anime(CuneiModel):
id = AutoIncrementField()
stid = IntegerField()
code = CharField(default="")
name = CharField(default="")
type = CharField(default="")
Publisher = CharField(default="")
writer = CharField(default="", null=True)
class Meta:
database = SqliteExtDatabase(None)
ฟังก์ชั่นการใช้งานและชนิดช้อมูล
- คำสั่งในการใช้งาน
'AutoIncrementField()': กำหนดให้มีรันตัวเลขอัตโนมัติ'null': กำหนดให้databaseสามารถเว้นว่างได้'SqliteExtDatabase': เปิดdatabase
- กำหนดชนิดของข้อมูล
'IntegerField()': ตัวแปรชนิดตัวเลขที่เป็นจำนวนเต็ม'FloatField()': ตัวแปรชนิดตัวเลขที่จุดทศนิยม'CharField()': ตัวแปรชนิดที่เป็นตัวอักษร'TextField()': ตัวแปรชนิดที่เป็นตัวอักษรและช่องข้อความขยายได้'DateField()': ?
Table.py
class Anime_table(CunriTble):
MASTER_colsizes = [1,3,10,10,0,7,7,7]
MASTER_colnames = ["stid", "code", "name", "type", "publisher_stid", "publisher_code", "publisher_name", "writer"]
MASTER_coltypes = ["int", "str", "str", "sel", "int", "str", "str", "str"]
MASTER_choicecols = ["type"]
MASTER_choices = [[("Comedy", "Comedy"), ("Action", "Action"), ("Fiction", "Fiction"), ("Fantasy", "Fantasy"), ("Adventure", "Adventure")]]
MASTER_schfill = {"publisher_code":["ModalPublisher:code", "publisher_stid:stid,publisher_name:name"]}
class SubForm(FlaskForm, CuneiSubForm):
stid = StringField("")
code = StringField("", validators=[InputRequired("Required!")])
name = StringField("", validators=[InputRequired("Required!")])
type = SelectField("")
# publisher = StringField("")
publisher_stid = StringField("Publisher StID", validators=[InputRequired(lazy_gettext("Required!"))], render_kw={"readonly":""})
publisher_code = StringField("Publisher Code", validators=[InputRequired(lazy_gettext("Required!"))])
publisher_name = StringField("Publisher Name", render_kw={"readonly":""})
writer = StringField("", validators=[InputRequired("Required!")])
def validate_writer(self, writer):
if len(writer.data) <= 1:
raise ValidationError(lazy_gettext("Very short"))