photoprism/internal/models/label.go
Michael Mayer 27ca260942 Indexing: Add "convert to jpeg" and "create thumbnails" options
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2019-12-11 04:12:54 +01:00

49 lines
1.1 KiB
Go

package models
import (
"strings"
"github.com/gosimple/slug"
"github.com/jinzhu/gorm"
)
// Labels for photo, album and location categorization
type Label struct {
Model
LabelSlug string `gorm:"type:varchar(128);index;"`
LabelName string `gorm:"type:varchar(128);"`
LabelPriority int
LabelFavorite bool
LabelDescription string `gorm:"type:text;"`
LabelNotes string `gorm:"type:text;"`
LabelCategories []*Label `gorm:"many2many:categories;association_jointable_foreignkey:category_id"`
New bool `gorm:"-"`
}
func NewLabel(labelName string, labelPriority int) *Label {
labelName = strings.TrimSpace(labelName)
if labelName == "" {
labelName = "Unknown"
}
labelSlug := slug.Make(labelName)
result := &Label{
LabelName: labelName,
LabelSlug: labelSlug,
LabelPriority: labelPriority,
}
return result
}
func (m *Label) FirstOrCreate(db *gorm.DB) *Label {
db.FirstOrCreate(m, "label_slug = ?", m.LabelSlug)
return m
}
func (m *Label) AfterCreate(scope *gorm.Scope) error {
return scope.SetColumn("New", true)
}