Add
This commit is contained in:
parent
54f2290bbd
commit
dbee524a31
|
|
@ -10,97 +10,97 @@ class Command(BaseCommand):
|
||||||
help = 'Import collection'
|
help = 'Import collection'
|
||||||
|
|
||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
# raw_qs = Collections.objects.raw('''
|
raw_qs = Collections.objects.raw('''
|
||||||
# select
|
select
|
||||||
# distinct
|
distinct
|
||||||
# a.id,
|
a.id,
|
||||||
# a.collection_id,
|
a.collection_id,
|
||||||
# -- a.establishment_id,
|
-- a.establishment_id,
|
||||||
# a.title,
|
a.title,
|
||||||
# a.tag_name,
|
a.tag_name,
|
||||||
# a.slug,
|
a.slug,
|
||||||
# -- a.attachment_file_name,
|
-- a.attachment_file_name,
|
||||||
# -- a.attachment_content_type,
|
-- a.attachment_content_type,
|
||||||
# -- a.attachment_file_size,
|
-- a.attachment_file_size,
|
||||||
# -- a.attachment_suffix_url,
|
-- a.attachment_suffix_url,
|
||||||
# -- active as is_publish,
|
-- active as is_publish,
|
||||||
# a.country_code,
|
a.country_code,
|
||||||
# -- a.geometries,
|
-- a.geometries,
|
||||||
# a.description,
|
a.description,
|
||||||
# min(a.start) AS start
|
min(a.start) AS start
|
||||||
# from
|
from
|
||||||
# (
|
(
|
||||||
# select distinct
|
select distinct
|
||||||
# c.id,
|
c.id,
|
||||||
# c.id as collection_id,
|
c.id as collection_id,
|
||||||
# m.establishment_id,
|
m.establishment_id,
|
||||||
# c.title, c.tag_name,
|
c.title, c.tag_name,
|
||||||
# c.slug, c.attachment_file_name,
|
c.slug, c.attachment_file_name,
|
||||||
# c.attachment_content_type, c.attachment_file_size,
|
c.attachment_content_type, c.attachment_file_size,
|
||||||
# c.attachment_suffix_url,
|
c.attachment_suffix_url,
|
||||||
# active,
|
active,
|
||||||
# s.country_code_2 as country_code,
|
s.country_code_2 as country_code,
|
||||||
# c.geometries,
|
c.geometries,
|
||||||
# c.title as description,
|
c.title as description,
|
||||||
# m.created_at as start
|
m.created_at as start
|
||||||
# from collections as c
|
from collections as c
|
||||||
# join metadata m on m.value = c.tag_name
|
join metadata m on m.value = c.tag_name
|
||||||
# join establishments e on e.id = m.establishment_id
|
join establishments e on e.id = m.establishment_id
|
||||||
# join sites s on s.id = c.site_id
|
join sites s on s.id = c.site_id
|
||||||
# where m.`key` = 'collection'
|
where m.`key` = 'collection'
|
||||||
#
|
|
||||||
# union
|
union
|
||||||
#
|
|
||||||
# select distinct
|
select distinct
|
||||||
# c.id,
|
c.id,
|
||||||
# c.id as collection_id,
|
c.id as collection_id,
|
||||||
# m.establishment_id,
|
m.establishment_id,
|
||||||
# c.title, c.tag_name,
|
c.title, c.tag_name,
|
||||||
# c.slug, c.attachment_file_name,
|
c.slug, c.attachment_file_name,
|
||||||
# c.attachment_content_type, c.attachment_file_size,
|
c.attachment_content_type, c.attachment_file_size,
|
||||||
# c.attachment_suffix_url,
|
c.attachment_suffix_url,
|
||||||
# active,
|
active,
|
||||||
# s.country_code_2 as country_code,
|
s.country_code_2 as country_code,
|
||||||
# c.geometries,
|
c.geometries,
|
||||||
# c.title as description,
|
c.title as description,
|
||||||
# m.created_at as start
|
m.created_at as start
|
||||||
# from collections as c
|
from collections as c
|
||||||
# join metadata m on m.value = c.slug
|
join metadata m on m.value = c.slug
|
||||||
# join establishments e on e.id = m.establishment_id
|
join establishments e on e.id = m.establishment_id
|
||||||
# join sites s on s.id = c.site_id
|
join sites s on s.id = c.site_id
|
||||||
# where m.`key` = 'collection'
|
where m.`key` = 'collection'
|
||||||
# ) a
|
) a
|
||||||
# group by
|
group by
|
||||||
# a.id,
|
a.id,
|
||||||
# a.collection_id,
|
a.collection_id,
|
||||||
# -- a.establishment_id,
|
-- a.establishment_id,
|
||||||
# a.title,
|
a.title,
|
||||||
# a.tag_name,
|
a.tag_name,
|
||||||
# a.slug,
|
a.slug,
|
||||||
# -- a.attachment_file_name,
|
-- a.attachment_file_name,
|
||||||
# -- a.attachment_content_type,
|
-- a.attachment_content_type,
|
||||||
# -- a.attachment_file_size,
|
-- a.attachment_file_size,
|
||||||
# -- a.attachment_suffix_url,
|
-- a.attachment_suffix_url,
|
||||||
# -- active as is_publish,
|
-- active as is_publish,
|
||||||
# a.country_code,
|
a.country_code,
|
||||||
# a.description
|
a.description
|
||||||
# ''')
|
''')
|
||||||
# objects = []
|
objects = []
|
||||||
# queryset = [vars(query) for query in raw_qs]
|
queryset = [vars(query) for query in raw_qs]
|
||||||
# for obj in queryset:
|
for obj in queryset:
|
||||||
# # establishment = Establishment.objects.filter(old_id=obj['establishment_id']).first()
|
# establishment = Establishment.objects.filter(old_id=obj['establishment_id']).first()
|
||||||
# lang = Language.objects.filter(locale=obj['country_code'])
|
lang = Language.objects.filter(locale=obj['country_code'])
|
||||||
# country = Country.objects.filter(languages__in=lang).first()
|
country = Country.objects.filter(languages__in=lang).first()
|
||||||
# if country:
|
if country:
|
||||||
# objects.append(
|
objects.append(
|
||||||
# Collection(name={"en-GB": obj['title']}, collection_type=Collection.ORDINARY,
|
Collection(name={"en-GB": obj['title']}, collection_type=Collection.ORDINARY,
|
||||||
# country=country,
|
country=country,
|
||||||
# description=obj['description'],
|
description=obj['description'],
|
||||||
# slug=obj['slug'], old_id=obj['collection_id'],
|
slug=obj['slug'], old_id=obj['collection_id'],
|
||||||
# start=obj['start']
|
start=obj['start']
|
||||||
# )
|
)
|
||||||
# )
|
)
|
||||||
# Collection.objects.bulk_create(objects)
|
Collection.objects.bulk_create(objects)
|
||||||
|
|
||||||
raw_qs = Collections.objects.raw('''
|
raw_qs = Collections.objects.raw('''
|
||||||
select
|
select
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user