def blog_search(x):
    with connection.cursor() as cursor:
        # Create a new record
        sql = """SELECT * from blog_project.blogs1 WHERE title LIKE %s"""
        cursor.execute(sql, ("%" + x + "%"))
    connection.commit()
    return cursor.fetchall()
def blog_delete(id):
    with connection.cursor() as cursor:
        # Create a new record
        sql = """delete from blog_project.blogs1 where id=%s"""
        cursor.execute(sql, id)
    connection.commit()
    return cursor.fetchone()
def blog_update(title, description, owner_name, id, **kwargs):
    with connection.cursor() as cursor:
        # Create a new record
        sql = "Update blog_project.blogs1 Set title=%s, description=%s, owner_name=%s where id =%s"
        now = datetime.now()
        created_ad = now.strftime('%Y-%m-%d %H:%M:%S')
        cursor.execute(sql, (title, description, owner_name, id))
    connection.commit()
def create_website_table():
    with connection.cursor() as cursor:
        # Create a new record
        sql = """insert into blog_project.about_website(social_adress, email,phone_number)
            values('Blog.com', 'Blog@gmail','+994000000') 
            """
        cursor.execute(sql)
    connection.commit()
Пример #5
0
def create_users_table():
    with connection.cursor() as cursor:
        # Create a new record
        sql = """create table if not exists users(
            id int(11) unsigned AUTO_INCREMENT PRIMARY KEY,
            username varchar(50) NOT NULL UNIQUE,
            email varchar(40) NOT NULL UNIQUE,
            first_name varchar(40) NOT NULL,
            surname varchar(40) NOT NULL,
            password varchar(255) NOT NULL,
            date_joined datetime NOT NULL,
            is_active tinyint(1) default 0
            );
            """
        cursor.execute(sql)
    connection.commit()
def create_blog_table():
    with connection.cursor() as cursor:
        # Create a new record
        sql = """create table if not exists blogs1(
            id int(11) unsigned AUTO_INCREMENT PRIMARY KEY,
            title varchar(255) NOT NULL,
            description text NOT NULL,
            user_id int(11) unsigned NOT NULL,
            image varchar(500),
            created_at datetime NOT NULL,
            is_published tinyint(1) default 1,
            FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE,
            INDEX (id, user_id)
            ); 
            """
        cursor.execute(sql)
    connection.commit()
def create_blog(title,
                description,
                user_id,
                image,
                is_published=True,
                **kwargs):
    with connection.cursor() as cursor:
        # Create a new record
        sql = """insert into blog_project.blogs1(title, description, user_id, image, created_at, is_published)
            values(%s, %s, %s, %s, %s, %s) 
            """
        now = datetime.now()
        created_ad = now.strftime('%Y-%m-%d %H:%M:%S')
        cursor.execute(
            sql,
            (title, description, user_id, image, created_ad, is_published))
    connection.commit()
Пример #8
0
def create_user(username,
                email,
                first_name,
                surname,
                password,
                is_active=1,
                **kwargs):
    hashed_pass = generate_password_hash(password)
    with connection.cursor() as cursor:
        # Create a new record
        sql = """INSERT INTO users(username, email, first_name, surname, password, date_joined, is_active)
            VALUES(%s, %s, %s, %s, %s, %s, %s);
        """
        now = datetime.now()
        date_joined = now.strftime('%Y-%m-%d %H:%M:%S')
        cursor.execute(sql, (username, email, first_name, surname, hashed_pass,
                             date_joined, is_active))
    connection.commit()