@@ -62,7 +62,39 @@ class Image(db.Model):
62
62
id = db .Column (UUID (), primary_key = True , server_default = func .uuid_generate_v4 ())
63
63
64
64
author_id = db .Column (None , db .ForeignKey ("users.discord_id" , ondelete = "CASCADE" ), nullable = False )
65
- author = relationship (User , backref = backref ("writeups " , passive_deletes = True ), lazy = "joined" )
65
+ author = relationship (User , backref = backref ("images " , passive_deletes = True ), lazy = "joined" )
66
66
67
67
filetype = db .Column (db .Text (), nullable = False )
68
68
image = db .Column (db .LargeBinary (), nullable = False )
69
+
70
+
71
+ class Blog (db .Model ):
72
+ __tablename__ = "blogs"
73
+
74
+ id = db .Column (db .Integer , primary_key = True )
75
+
76
+ title = db .Column (db .Text (), nullable = False , unique = True )
77
+ slug = db .Column (db .Text (), nullable = False , unique = True )
78
+
79
+ tags = db .Column (ARRAY (db .Text ()), nullable = False )
80
+ content = db .Column (db .Text (), nullable = False )
81
+
82
+ creation_date = db .Column (db .DateTime , server_default = func .now (), nullable = False )
83
+ edit_date = db .Column (db .DateTime , server_default = func .now (), server_onupdate = func .now (), nullable = False )
84
+
85
+ search_vector = db .Column (
86
+ TSVectorType ("title" , "content" , weights = {"title" : "A" , "content" : "B" })
87
+ )
88
+
89
+ _tags_idx = db .Index ("blogs_tags_array_idx" , "tags" , postgresql_using = "gin" )
90
+
91
+ @classmethod
92
+ def create_auto (cls , * args , ** kwargs ):
93
+ if "slug" not in kwargs :
94
+ kwargs ["slug" ] = slug (kwargs ["title" ])
95
+ return cls .create (* args , ** kwargs )
96
+
97
+ def update_auto (self , * args , ** kwargs ):
98
+ if "slug" not in kwargs :
99
+ kwargs ["slug" ] = slug (kwargs ["title" ])
100
+ return self .update (* args , ** kwargs )
0 commit comments