from django.core.management.base import BaseCommand, CommandError from datetime import date from heasarc.models import INPUT_DATA_DIR import datetime from django.utils import timezone import astropy from astropy.io import ascii import pandas as pd import pymysql from sqlalchemy import create_engine import numpy.ma as ma from astrobasis.models import GaiaSourceFile, GAIADR2 from astropy_healpix import HEALPix from astropy.coordinates import SkyCoord # High-level coordinates from astropy.coordinates import ICRS, Galactic, FK4, FK5 # Low-level frames from astropy.coordinates import Angle, Latitude, Longitude # Angles import astropy.units as u import os import glob import logging def delete_gaia(): gaia_loaded = GaiaSourceFile.objects.all() #filter(status__exact='loaded') total_loaded = gaia_loaded.count() total = 0 for gaia in gaia_loaded: total_linked = gaia.gaiadr2_set.all().count() print("%s %s linked: %d nrows: %d" % (gaia.filename, gaia.status,total_linked,gaia.nrows)) linked = gaia.gaiadr2_set.all() linked.delete() gaia.status='empty' gaia.save() total+=1 print("Total %d removed from %d" % (total, total_loaded,)) pass class Command(BaseCommand): help = 'Initiates data dase' def handle(self, *args, **options): delete_gaia()