GithubHelp home page GithubHelp logo

jaymzcd / django-import-helpers Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 99 KB

Functions that are handy for me when importing data from various sources and at the start of django projects

Home Page: http://jaymz.eu

Python 100.00%

django-import-helpers's Introduction

Django Import Helpers

What?

These are scripts that I use from a django shell via iPython. Often when we're importing data to a site from an existing source/model/sql/spreadsheet there's some tidy up required to get the data fully clean. These are general scripts I use to aid that process.

In all cases the module & model_class arguments are used to dynamically import the django model class and get|set-attr are used so you can use these functions with anything you would normally import and operate on via the shell.

Functions

assign_file_to_model

assign_file_to_model(module, model_class=None, file_field='main_image', source_field='body', skip_existing=True, verbose=False):

Uses the source field to find the first image tag, download that to tmp and then assign it via django's Files so you end up with the correct paths and the media in your upload_to path for the object instance.

slug_model

slug_model(module, model_class=None, slug_field='slug', source_field='name', skip_existing=True, verbose=False)`

Uses a given field to create a slug which is then assigned to the slug_field. If the db complains of IntegrityErrors when saving it will append a hash of the current time and append that and try again to force uniqueness.

django-import-helpers's People

Contributors

jaymzcd avatar tomviner avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

tomviner

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.