Document System Tutorial Part 4 - Creating Records in Folders (Current Progress)¶
Structure:
models¶
folder_group.go¶
package models
import (
"github.com/uadmin/uadmin"
)
// FolderGroup !
type FolderGroup struct {
uadmin.Model
Group uadmin.UserGroup
GroupID uint
Folder Folder
FolderID uint
Read bool
Add bool
Edit bool
Delete bool
}
// FolderGroup function that returns string value
func (f *FolderGroup) String() string {
// Gives access to the fields in another model
uadmin.Preload(f)
// Returns the GroupName from the Group model
return f.Group.GroupName
}
folder_user.go¶
package models
import (
"github.com/uadmin/uadmin"
)
// FolderUser !
type FolderUser struct {
uadmin.Model
User uadmin.User
UserID uint
Folder Folder
FolderID uint
Read bool
Add bool
Edit bool
Delete bool
}
// FolderUser function that returns string value
func (f *FolderUser) String() string {
// Gives access to the fields in another model
uadmin.Preload(f)
// Returns the full name from the User model
return f.User.String()
}
folder.go¶
package models
import (
"github.com/uadmin/uadmin"
)
// Folder !
type Folder struct {
uadmin.Model
Name string
Parent *Folder
ParentID uint
}
main.go¶
package main
import (
// Specify the username that you used inside github.com folder
"github.com/username/document_system/models"
"github.com/uadmin/uadmin"
)
func main() {
// Register models to uAdmin
uadmin.Register(
models.Folder{},
models.FolderGroup{},
models.FolderUser{},
)
// Assign Site Name value as "Document System"
// NOTE: This code works only if database does not exist yet.
uadmin.SiteName = "Document System"
// Activates a uAdmin server
uadmin.StartServer()
}