#更改数据库
This commit is contained in:
parent
589839e175
commit
de3dea2798
|
@ -101,7 +101,7 @@ CHANNEL_LAYERS = {
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||||
'NAME': 'newmediaDB3',
|
'NAME': 'newmediaDB1',
|
||||||
'USER': 'newmedia',
|
'USER': 'newmedia',
|
||||||
'PASSWORD': 'newmedia2020!@#',
|
'PASSWORD': 'newmedia2020!@#',
|
||||||
'HOST': '210.77.68.250',
|
'HOST': '210.77.68.250',
|
||||||
|
|
|
@ -106,8 +106,8 @@ class Organization(models.Model):
|
||||||
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||||
name = models.CharField('单位名', max_length=256, null=True, blank=True)
|
name = models.CharField('单位名', max_length=256, null=True, blank=True)
|
||||||
image = models.FileField(upload_to='cover', null=True, blank=True)
|
image = models.FileField(upload_to='cover', null=True, blank=True)
|
||||||
organizationtype = models.ForeignKey(
|
# organizationtype = models.ForeignKey(
|
||||||
Organizationtype, on_delete=models.CASCADE, null=True, blank=True)
|
# Organizationtype, on_delete=models.CASCADE, null=True, blank=True)
|
||||||
province = models.CharField('省', max_length=256, null=True, blank=True)
|
province = models.CharField('省', max_length=256, null=True, blank=True)
|
||||||
cities = models.CharField('市', max_length=256, null=True, blank=True)
|
cities = models.CharField('市', max_length=256, null=True, blank=True)
|
||||||
district = models.CharField('县', max_length=256, null=True, blank=True)
|
district = models.CharField('县', max_length=256, null=True, blank=True)
|
||||||
|
@ -117,6 +117,10 @@ class Organization(models.Model):
|
||||||
Level, on_delete=models.CASCADE, null=True, blank=True)
|
Level, on_delete=models.CASCADE, null=True, blank=True)
|
||||||
directly = models.CharField('单位类型', max_length=256, null=True, blank=True)
|
directly = models.CharField('单位类型', max_length=256, null=True, blank=True)
|
||||||
status = models.CharField('状态', max_length=256, null=True, blank=True)
|
status = models.CharField('状态', max_length=256, null=True, blank=True)
|
||||||
|
|
||||||
|
#20201014新添加字段
|
||||||
|
id_code = models.CharField('单位唯一标识码',max_length=256,null=True,blank=True)
|
||||||
|
|
||||||
created = models.DateTimeField('创建时间', auto_now_add=True)
|
created = models.DateTimeField('创建时间', auto_now_add=True)
|
||||||
updated = models.DateTimeField('更新时间', auto_now=True)
|
updated = models.DateTimeField('更新时间', auto_now=True)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import csv
|
||||||
|
import uuid
|
||||||
|
import os
|
||||||
|
import psycopg2
|
||||||
|
|
||||||
|
from pip._vendor import chardet
|
||||||
|
|
||||||
|
# G1 = 'host=210.77.68.250 port=5432 dbname=g214_test user=g214 password=g214G214'
|
||||||
|
G2 = 'host=210.77.68.250 port=5432 dbname=newmediaDB3 user=newmedia password=newmedia2020!@#'
|
||||||
|
|
||||||
|
def get_organizationtype_id(name,image,province,cities,district,directly,status,level_id,id_code):
|
||||||
|
with psycopg2.connect(G2) as connection:
|
||||||
|
with connection.cursor() as cursor:
|
||||||
|
id = uuid.uuid4()
|
||||||
|
cursor.execute(
|
||||||
|
"insert into dashboard_organization(id,name,image, province, cities, district, town,village,directly,status,level_id,id_code, created, updated) values (%s,%s, %s,%s,%s,%s,'','', %s,%s,%s,%s,now(),now())"
|
||||||
|
, (str(id), name,image,province,cities,district,directly,status,level_id,id_code))
|
||||||
|
connection.commit()
|
||||||
|
print(name)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
with open('D:/2020/舆论监测平台/XMTJC/数据/总.csv',encoding='utf-8') as csvfile:
|
||||||
|
reader = csv.reader(csvfile)
|
||||||
|
for r in reader:
|
||||||
|
if r[1] != '单位全称':
|
||||||
|
print(r)
|
||||||
|
name = r[1]
|
||||||
|
image = 'danweimoren.jpg'
|
||||||
|
province = '甘肃省'
|
||||||
|
cities = r[10]
|
||||||
|
district = r[11]
|
||||||
|
directly = r[6]
|
||||||
|
status = 1
|
||||||
|
level_id = '69be9ef4-b7b7-4049-a86e-7083bee40f0e'
|
||||||
|
id_code = r[2]
|
||||||
|
get_organizationtype_id(name,image,province,cities,district,directly,status,level_id,id_code)
|
Loading…
Reference in New Issue