Skip to content

Instantly share code, notes, and snippets.

@gordonje
Last active February 7, 2016 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gordonje/7b5cfd22e2800f602273 to your computer and use it in GitHub Desktop.
Save gordonje/7b5cfd22e2800f602273 to your computer and use it in GitHub Desktop.
for checking tsv lines while cleaning.
# django-calaccess-raw-data/calaccess_raw/__init__.py
def get_model_from_file_name(file_name):
"""
Returns a calaccess_raw model to which the given .CSV or .TSV file maps
"""
from django.apps import apps
import re
model_name = re.sub(r'\.\w+', '', file_name).title().replace('_', '')
return apps.get_app_config("calaccess_raw").get_model(model_name)
# ...
from calaccess_raw import get_download_directory, get_model_from_file_name
#...
class Command(CalAccessCommand):
# ...
def handle(self, *args, **options):
# ...
for tsv_line in tsv_file:
# ...
line_dict = dict(zip(field_names, csv_field_list))
model = get_model_from_file_name(self.file_name)
model_inst = model(**line_dict)
model_inst.clean_fields()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment