uadmin.Schema

Back to Customizing Records Page

Schema is the global schema of the system.

Structure:

map[string]uadmin.ModelSchema

Used in the tutorial:

Examples:

Approval

Back to Top

A feature used to set an approval permission in the field

Type:

bool

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Approval

Suppose you have “johndoe” account in the User model that is not an admin.

../../_images/johndoerecord.png

User permissions are set for that user in Approvals and Friends models without an approval access.

../../_images/johndoeuserpermissionapproval.png

And you have the Name field in the Friend model that has a primary key of 1 as shown below:

../../_images/friendnamedefault.png

Let’s set a feature for an approval permission in the field. In order to do that, create a schema function of Friend model where the field name is Name then access Approval.

func main(){
    // Some codes

    // friend - Model Name
    // Name - Field Name
    uadmin.Schema["friend"].FieldByName("Name").Approval = true
}

Run your application and login your account using “johndoe”.

../../_images/johndoelogin.png

As you can see, only the Approvals and Friends models are accessible in the dashboard. It is based on the user permission that was assigned on that user. Now click on “FRIENDS”.

../../_images/friendsapprovalhighlighted.png

Click “Add New Friend” to create a new record.

../../_images/addnewfriend.png

Let’s input the following field for this record.

../../_images/johndoefriendrecord.png

Result

../../_images/johndoenameempty.png

Based on the result, the name does not show up because we need an approval to someone who has approval access. Now logout johndoe account then login an admin account.

../../_images/loginformadmin.png

From uAdmin dashboard, go to the Friends model, click the record that you have created, and in the input box of the Name field, there is a yellow warning sign on the left side that means it needs an approval to someone who has approval access. Now click the highlighted area below.

../../_images/johndoeapprovalbutton.png

The admin will review the record that was created by a “johndoe” user. If you think his record is satisfactory, choose Approved in Approval Action then click Save and Continue on the bottom right corner of the screen.

../../_images/johndoeapprovalreview.png

It is shown that the one who approved the record is an admin with an approved date. Now click View Record button to see the result.

../../_images/johndoeviewrecord.png

The input Name field has a checkmark sign that means the record created by “johndoe” was approved.

../../_images/johndoeapprovedrecord.png

CategoricalFilter

Back to Top

A section of code that is designed to process user input and output request to produce a new data structure containing exactly those elements of the original data structure in the form of combo box

Type:

bool

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").CategoricalFilter

See Filter for the example.

Choices

Back to Top

A struct for the list of choices

Type:

[]uadmin.Choice

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Choices

Suppose you have the given source code in friend.go where Nationality is the type of the drop down list:

// Nationality ...
type Nationality int

// Chinese ...
func (Nationality) Chinese() Nationality {
    return 1
}

// Filipino ...
func (Nationality) Filipino() Nationality {
    return 2
}

// Others ...
func (Nationality) Others() Nationality {
    return 3
}

Let’s build a choice that includes Chinese and Filipino and excludes Others. In order to do that, create a schema function of Friend model where the field name is Nationality then access Choices.

func main(){
    // Some codes

    // friend - Model Name
    // Nationality - Field Name
    uadmin.Schema["friend"].FieldByName("Nationality").Choices = []uadmin.Choice{
        // K is the ID of the choice.
        // V is the value of the choice.
        {K: 0, V: " - "},
        {K: 1, V: "Chinese"},
        {K: 2, V: "Filipino"},
    }
}

Run your application, go to the Friend model and click Add New Friend button on the top right corner of the screen. As expected, Chinese and Filipino choices are included in the list.

../../_images/friendnationalitychoices.png

DefaultValue

Back to Top

A value assigned automatically if you want to add a new record

Type:

string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").DefaultValue

Let’s set a feature that assigns a value automatically when creating a new record. In order to do that, create a schema function of Friend model where the field name is Nationality then access DefaultValue.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").DefaultValue = "Type here"
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, “Type here” value has assigned automatically in the Name field.

../../_images/categorydefaultvalue.png

DisplayName

Back to Top

The name that you want to display in the model. It is an alias name.

Type:

string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").DisplayName

Let’s replace the actual field name. In order to do that, create a schema function of Category model where the field name is Name then access DisplayName.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").DisplayName = "Display Name"
}

Run your application and go to Category model. As expected, the name has changed to “CATEGORY NAME”.

../../_images/categorydisplayname.png

Encrypt

Back to Top

A feature used to encrypt the value in the database

Type:

bool

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Encrypt

Suppose you have two records in the Category model as shown below:

../../_images/categorynametworecords.png

Let’s encrypt the value of the Name field in the Category Model. In order to do that, create a schema function of Category model where the field name is Name then access Encrypt.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").Encrypt = true
}

Run your application. From your project folder, open uadmin.db with DB Browser for SQLite.

../../_images/uadmindbsqlite.png

Click on Execute SQL.

../../_images/executesqlhighlighted.png

Get all records by typing this command: SELECT * FROM categories then click the right arrow icon to execute your SQL command.

../../_images/selectfromcategories.png

As expected, the Name value is encrypted in the database.

../../_images/categorynameencrypt.png

ErrMsg

Back to Top

An error message displayed beneath the input field

Type:

string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").ErrMsg

Let’s set a feature where an error message will be displayed beneath the input Name field. In order to do that, create a schema function of Category model where the field name is Name then access ErrMsg.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").ErrMsg = "This field cannot be modified."
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the error message was displayed beneath the input Name field.

../../_images/categorynameerrmsg.png

Filter

Back to Top

A section of code that is designed to process user input and output request to produce a new data structure containing exactly those elements of the original data structure in the form of fill-up text

Type:

bool

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Filter

Let’s set a feature where the user can filter the name in the Category model. In order to do that, create a schema function of Category model where the field name is Name then access Filter for input and CategoricalFilter for display.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").Filter = true
    uadmin.Schema["category"].FieldByName("Name").CategoricalFilter = true
}

Run your application and go to the Category model. As expected, the combo box form highlighted on the right side is the CategoricalFilter to notify the user that the Category Name is the field that will be filtered. Now click the Filter button. Suppose you have two records as shown below:

../../_images/categoryfilter.png

Assign “Work” in the Category Name. Click Filter button on the bottom right corner of the modal and see what happens.

../../_images/categoryfilterwork.png

As expected, the Category record has filtered out where the name contains “Work”.

../../_images/categorynamefilterresult.png

FormDisplay

Back to Top

A feature that will hide the field in the editing section of the model if the value returns false

Type:

bool

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").FormDisplay

Let’s set a feature that will hide the field in the editing section of the Category model. In order to do that, create a schema function of Category model where the field name is Name then access FormDisplay.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").FormDisplay = false
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the Name Field is now invisible in the Category model.

../../_images/categorynameformdisplay.png

Help

Back to Top

A feature that gives solution(s) to solve advanced tasks

Type:

string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Help

Let’s assign a help note in the Name field to instruct the user what to do on that field. In order to do that, create a schema function of Category model where the field name is Name then access Help.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").Help = "Input a category name for your Todo List."
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the help note was displayed below the input Name field.

../../_images/categorynamehelp.png

Hidden

Back to Top

A feature to hide the component in the editing section of the form

Type:

bool

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Hidden

Unlike in FormDisplay, the field will hide if the value is true. In order to hide the Name field in the Category model, create a schema function of Category model where the field name is Name then access Hidden.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").Hidden = true
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the Name Field is now invisible in the Category model.

../../_images/categorynameformdisplay.png

ListDisplay

Back to Top

A feature that will hide the field in the viewing section of the model if the value returns false

Type:

bool

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").ListDisplay

Let’s set a feature that will hide the field or column name in the viewing section of the Category model. In order to hide the Name field in the Category model, create a schema function of Category model where the field name is Name then access ListDisplay.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").ListDisplay = false
}

Run your application and go to the Category model. As expected, the Name Field in Category Model is now invisible in the list.

../../_images/categorynamelistdisplay.png

Max

Back to Top

The maximum value the user can assign. It is applicable for numeric characters.

Type:

interface{}

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Max

Let’s set a limitation where the user can assign a value up to 100. In order to do that, create a schema function of Todo model where the field name is Progress then access Max.

func main(){
    // Some codes

    // todo - Model Name
    // Progress - Field Name
    uadmin.Schema["todo"].FieldByName("Progress").Max = "100"
}

Run your application and go to the Todo model. Let’s put a numeric value beyond the maximum limit in the Progress field and see what happens.

../../_images/todoprogressmax.png

Min

Back to Top

The minimum value the user can assign. It is applicable for numeric characters.

Type:

interface{}

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Min

Let’s set a limitation where the user can assign a value at least 0. In order to do that, create a schema function of Todo model where the field name is Progress then access Min.

func main(){
    // Some codes

    // todo - Model Name
    // Progress - Field Name
    uadmin.Schema["todo"].FieldByName("Progress").Min = "0"
}

Run your application and go to the Todo model. Let’s put a numeric value beyond the minimum limit in the Progress field and see what happens.

../../_images/todoprogressmin.png

Pattern

Back to Top

A regular expression

Type:

string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Pattern

Let’s set a feature where the user can assign letters only in the Name field. In order to do that, create a schema function of Category model where the field name is Name then access Pattern for regular expression and PatternMsg for an error message if the user did not match the requested format.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").Pattern = "^[a-zA-Z _]*$"
    uadmin.Schema["category"].FieldByName("Name").PatternMsg = "Your input must be a letter."
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. Let’s assign a numeric value in the Name field. If you click Save, the system will prompt the user the the value of the Name field must assign letters only.

../../_images/categorynamepattern.png

PatternMsg

Back to Top

An error message if the user assigns a value that did not match the requested format

Type:

string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").PatternMsg

See Pattern for an example.

ProgressBar

Back to Top

A feature used to measure the progress of the activity

Type:

map[float64]string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").ProgressBar

Let’s assign the value and the color of the progress bar. In order to do that, create a schema function of Todo model where the field name is Progress then access ProgressBar.

func main(){
    // Some codes

    // todo - Model Name
    // Progress - Field Name
    // 100.0 - maximum value
    // #07c - blue color
    uadmin.Schema["todo"].FieldByName("Progress").ProgressBar = map[float64]string{100.0: "#07c"}
}

Run your application and go to the Todo model. As expected, the assigned values were applied to the progress bar.

../../_images/todoprogressbar.png

ReadOnly

Back to Top

A field that cannot be modified

Type:

string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").ReadOnly

Let’s set a feature where the user cannot modify a Name field in the Category model. In order to do that, create a schema function of Category model where the field name is Name then access ReadOnly.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").ReadOnly = "true"
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. As expected, the Name field is now Read Only that means the value cannot be modified.

../../_images/categorynamereadonly.png

Required

Back to Top

A field that user must perform the given task(s). It cannot be skipped or left empty.

Type:

bool

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Required

Let’s set a feature where the user needs to fill up the Name field. If the value is empty, the user will prompt the user that the value of the Name field should be assigned. In order to do that, create a schema function of Category model where the field name is Name then access Required.

func main(){
    // Some codes

    // category - Model Name
    // Name - Field Name
    uadmin.Schema["category"].FieldByName("Name").Required = true
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. If you notice, there is an asterisk (*) symbol located on the top right after the “Name:”. Let’s leave the Name field value as it is. If you click Save, the system will prompt the user that the Name must be filled out.

../../_images/categorynamerequired.png

Stringer

Back to Top

A feature that assigns a field as a unique type

Type:

bool

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Stringer

Let’s set a feature that assigns a field as a unique type. In order to do that, create a schema function of Friend model where the field name is Name then access Stringer.

func main(){
    // Some codes

    // friend - Model Name
    // Name - Field Name
    uadmin.Schema["friend"].FieldByName("Name").Stringer = true
}

Go to uadmin.Stringer in the API Reference for the continuation.

Type

Back to Top

The field type (e.g. file, list, progress_bar)

Type:

string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Type

Suppose you have this field in the Todo model as shown below:

../../_images/todoprogressdefault.png

Let’s convert the input type to the progress bar. In order to do that, create a schema function of Todo model where the field name is Progress then access Type.

func main(){
    // Some codes

    // todo - Model Name
    // Progress - Field Name
    uadmin.Schema["todo"].FieldByName("Progress").Type = "progress_bar"
}

Run your application and go to the Todo model. As expected, the field type has changed from regular to a progress bar. However, the appearance does not look good because we have not assigned the value and color of the progress bar yet.

../../_images/todoprogresstype.png

Let’s improvise the appearance by assigning the value and the color of the progress bar. In order to do that, create a schema function of Todo model where the field name is Progress then access ProgressBar.

func main(){
    // Some codes

    // todo - Model Name
    // Progress - Field Name
    // 100.0 - maximum value
    // #07c - blue color
    uadmin.Schema["todo"].FieldByName("Progress").ProgressBar = map[float64]string{100.0: "#07c"}
}

Run your application and go to the Todo model. As expected, the appearance of the progress bar is now good enough.

../../_images/todoprogressbar.png

UploadTo

Back to Top

A path where to save the uploaded files

Type:

string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").UploadTo

Let’s set a feature where the uploaded file will save in the specified path on your project folder. In order to do that, create a schema function of Category model where the field name is File then access UploadTo.

func main(){
    // Some codes

    // category - Model Name
    // File - Field Name
    uadmin.Schema["category"].FieldByName("File").UploadTo = "/media/files/"
}

Run your application, go to the Category model and click Add New Category button on the top right corner of the screen. Let’s add a new record that includes the uploaded file from your computer (e.g. Windows Installation.pdf).

../../_images/categoryinstallationrecord1.png

Result:

../../_images/categoryinstallationrecordresult1.png

From your project folder, go to /media/files/(generated_folder_name)/. As expected, the “Windows Installation.pdf” file was saved on that path.

../../_images/categoryfileuploadto.png

WebCam

Back to Top

A feature which adds web can access directly from the image and file fields

Type:

string

Structure:

uadmin.Schema[ModelName].FieldByName("FieldName").Webcam

Let’s set a feature that accesses a webcam directly into the image field. In order to do that, create a schema function of Friend model where the field name is ProfilePic then access Webcam.

func main(){
    // Some codes

    // friend - Model Name
    // ProfilePic - Field Name
    uadmin.Schema["friend"].FieldByName("ProfilePic").Type = "image"
    uadmin.Schema["friend"].FieldByName("ProfilePic").WebCam = true
}

Run your application, go to the Friend model and click Add New Friend button on the top right corner of the screen. As expected, there is a camera tag on the right side of the ProfilePic input field. If you have a webcam installed on your computer, click that icon and see it for yourself.

../../_images/webcamiconhighlighted.png