forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo.go
36 lines (32 loc) · 945 Bytes
/
todo.go
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
package models
import (
"time"
"github.com/uadmin/uadmin"
)
// Todo model ...
type Todo struct {
uadmin.Model
Name string
Description string `uadmin:"html"`
Category Category
CategoryID uint
Friend Friend `uadmin:"help:Who will be a part of your activity?"`
FriendID uint
Item Item `uadmin:"help:What are the requirements needed in order to accomplish your activity?"`
ItemID uint
TargetDate time.Time
Progress int `uadmin:"progress_bar"`
}
// Validate function ...
func (t Todo) Validate() (errMsg map[string]string) {
// Initialize the error messages
errMsg = map[string]string{}
// Get any records from the database that maches the name of
// this record and make sure the record is not the record we are
// editing right now
todo := Todo{}
if uadmin.Count(&todo, "name = ? AND id <> ?", t.Name, t.ID) != 0 {
errMsg["Name"] = "This todo name is already in the system"
}
return
}