def handle(self, *args, **options): if Movie.objects.exists(): print('Movie data already loaded...exiting.') print(ALREADY_LOADED_ERROR_MESSAGE) return print("Creating movie data") for row in DictReader(open('./movies.csv')): movie = Movie() movie.title = row['Title'] #movie.movie_poster_image = models.ImageField(blank=True, null=True, #upload_to="posters/") movie.release_date = row['Release_date'] movie.director = row['Director'] movie.rating = row['Rating'] movie.genre = row['Genre'] movie.description = row['Description'] movie.save()
def create_or_update_movie_from_line(self, line): movie_parts_separator = " " self.stdout.write(u'Processing line {line}'.format(line=line)) movie_line_parts = filter(None, (line.split(movie_parts_separator))) title = movie_line_parts[3].split("\" (")[0][1:] year = movie_line_parts[3].split("\" (")[1][:-2] new_or_updated_movie = Movie() new_or_updated_movie.imdb_rank = float(movie_line_parts[2]) new_or_updated_movie.title = title new_or_updated_movie.year = year new_or_updated_movie.imdb_votes = int(movie_line_parts[1]) new_or_updated_movie.rating = new_or_updated_movie.imdb_rank new_or_updated_movie.total_votes = new_or_updated_movie.imdb_votes new_or_updated_movie.save() self.stdout.write(unicode(new_or_updated_movie)) self.stdout.write('')