You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
2.4 KiB

# -*- coding: utf-8 -*-
import MySQLdb
from MySQLdb.cursors import DictCursor
from django.core.management.base import BaseCommand, CommandError
from functions.translate import fill_with_signal
from article.models import Article
from accounts.models import User
class Command(BaseCommand):
def handle(self, *args, **options):
db = MySQLdb.connect(host="localhost",
user="kotzilla",
passwd="qazedc",
db="old_expomap",
charset='utf8',
cursorclass=DictCursor)
cursor = db.cursor()
sql = """SELECT articles_description.articles_id as id ,
articles_description.articles_name as main_title,
articles_description.articles_description as description,
articles.authors_id as author,
articles_description.articles_intro as preview,
articles.articles_date_added as created,
articles.articles_last_modified as modified,
articles.articles_date_available as publish_date,
articles_description.articles_head_title_tag as title,
articles_description.articles_head_desc_tag as descriptions,
articles_description.articles_head_keywords_tag as keywords
FROM `articles_description`
JOIN articles
ON articles_description.articles_id=articles.articles_id"""
cursor.execute(sql)
result = cursor.fetchall()
user = User.objects.get(id=1)
Article.objects.blogs().delete()
for a in result:
article = Article(type=Article.blog,
id=a['id'],
created=a['created'],
modified=a['modified'],
publish_date=a['publish_date'])
article.author = user
article.translate('ru')
article.main_title = a['main_title']
article.preview = a['preview']
article.description = a['description']
article.title = a['title']
article.keywords = a['keywords']
if len(a['descriptions'])<255:
article.descriptions = a['descriptions']
article.save()
print(article)
#print(a['main_title'])