コード例 #1
0
 def mutate(root, info, input=None):
     """
     :param root:
     :param info:
     :param input:
     :return:
     """
     ok = True
     actor_instance = Actor(name=input.name)
     actor_instance.save()
コード例 #2
0
ファイル: test_models.py プロジェクト: lype86/cine
class ActorTest(TestCase):
    def setUp(self):
        self.actor = Actor(
            name='Fulano',
            country='Brasil',
        )
        self.actor.save()

    def test_create(self):
        'Actor instance may be saved'
        self.assertEqual(1, self.actor.pk)

    def test_unicode(self):
        'Actor string representation may be the name.'
        self.assertEqual(u'Fulano', unicode(self.actor))
コード例 #3
0
ファイル: test_models.py プロジェクト: yannhamdi/projet13
 def test_product(self):
     category = Category.objects.create(cat="drama")
     self.assertEqual(category.cat, "drama")
     actors = Actor.objects.create(act="bruce willis")
     self.assertEqual(actors.act, "bruce willis")
     movie = Movie.objects.create(id_code=2344393, movie_title="die hard",run_time="103",movie_released="2005"
                                         ,image_movie="www.didjdijddj.com",plot="film de guerre et tirs")
     categ = Category.objects.get(cat=category.cat)
     movie.category.add(categ)
     movie.save()
     acto = Actor.objects.get(act=actors.act)
     movie.actor.add(acto)
     self.assertEqual(movie.id_code, 2344393)
     self.assertEqual(movie.movie_title, "die hard")
     self.assertEqual(movie.run_time, "103")
     self.assertEqual(movie.movie_released, "2005")
     self.assertEqual(movie.image_movie, "www.didjdijddj.com")
     self.assertEqual(movie.plot, "film de guerre et tirs")
     cate = movie.category.all()
     cate2= str(cate[0])
     aac = movie.actor.all()
     aac2 = str(aac[0])
     self.assertEqual(cate2, "drama")
     self.assertEqual(aac2, "bruce willis")
     self.assertEqual(movie.movie_title, Movie.__str__(movie))
     self.assertEqual(category.cat, Category.__str__(category))
     self.assertEqual(actors.act, Actor.__str__(actors))
コード例 #4
0
 def mutate(root, info, input=None):
     ok = True
     actor_instance = Actor(name=input.name)
     actor_instance.save()
     return CreateActor(ok=ok, actor=actor_instance)
コード例 #5
0
from movies.models import Movie, Actor
from datetime import date

# create 2 actors
a = Actor(first_name="Darren", last_name="Price")
a.save()

a2 = Actor(first_name="Darren2", last_name="Price2")
a2.save()

# create movie
m = Movie(title="Dumb", release_date=date(2016, 7, 8), rating=10, actor=a)
m.save()

a = m.actor

# create movie object via the actor object relationship
new_movie = a.movie_set.create(title="Dumb set using _set",
                               release_date=date(2016, 7, 8),
                               rating=10)

# adding a movie to the movie set (a movie set is defined for an actor)
m2 = Movie(title="Dumb and Dumberer", release_date=date(2016, 7, 8), rating=10)
m2.save()

# adding movie to a different actor has the effect of moving the movie to a different set
# this is Many to One!! so the movie cannot belong to two actors at once. We need Many to Many
a.movie_set.add(m2)

a2.movie_set.add(m2)
コード例 #6
0
 def handle(self, *args, **options):
     if Movie.objects.exists() or Actor.objects.exists(
     ) or Director.objects.exists() or Writer.objects.exists():
         print('Movie data already loaded...exiting.')
         print(ALREADY_LOADED_ERROR_MESSAGE)
         return
     print(
         "\nLoading Movie data for Movies available in movies_metadata.csv")
     i = 1
     for row in DictReader(open('./movies_metadata.csv')):
         print(i, end=', ')
         i += 1
         movie = Movie()
         movie.id = row['id']
         movie.title = row['title']
         movie.budget = 0 if row['budget'] == '' else row['budget']
         # genres is a list of dictionaries
         genres_raw = row['genres']
         genres_list = eval(genres_raw)
         genres_name_list = list()
         for genre in genres_list:
             genres_name_list.append(genre['name'])
         movie.genres = ','.join(genres_name_list)
         movie.language = row['original_language']
         movie.overview = row['overview']
         # companies is a list of dictionaries
         companies_raw = row['production_companies']
         companies_list = eval(companies_raw)
         companies_name_list = list()
         for company in companies_list:
             companies_name_list.append(company['name'])
         movie.companies = ','.join(companies_name_list)
         # countries is a list of dictionaries
         countries_raw = row['production_countries']
         countries_list = eval(countries_raw)
         countries_name_list = list()
         for country in countries_list:
             countries_name_list.append(country['name'])
         movie.countries = ','.join(countries_name_list)
         movie.release_date = row['release_date']
         movie.revenue = 0 if row['revenue'] == '' else row['revenue']
         movie.runtime = 0 if row['runtime'] == '' else row['runtime']
         movie.vote_average = 0 if row['vote_average'] == '' else row[
             'vote_average']
         movie.vote_count = 0 if row['vote_count'] == '' else row[
             'vote_count']
         try:
             # get the right picture for movie
             api_req = requests.get("https://api.themoviedb.org/3/movie/" +
                                    str(row['id']) + "?api_key=" +
                                    str(os.getenv('API_KEY')) +
                                    "&language=en-US")
             if api_req.json()['poster_path'] == None:
                 raise ValueError
             movie.poster = str(api_req.json()['poster_path'])
         except:
             print('failed at loading poster path from: ' +
                   "https://api.themoviedb.org/3/movie/" + str(row['id']) +
                   "?api_key=" + str(os.getenv('API_KEY')) +
                   "&language=en-US")
             movie.poster = row['poster_path']
         movie.save()
     print(
         "\nLoading Actor, Director, Writer data for Credits available in credits.csv"
     )
     SEX_CHOICES = {1: 'F', 2: 'M', 0: ''}
     i = 1
     for row in DictReader(open('./credits.csv')):
         print(i, end=', ')
         i += 1
         # import Actors
         actors_raw = row['cast']
         actors_list = eval(actors_raw)
         for each_actor in actors_list[:5]:
             # if we have the actor just add movie id to it
             try:
                 actor = Actor.objects.get(actor_id=each_actor['id'])
                 actor.movie_ids = actor.movie_ids + ',' + row['id']
             except:
                 actor = Actor()
                 actor.actor_id = each_actor['id']
                 actor.name = each_actor['name']
                 gender_raw = each_actor['gender']
                 actor.gender = SEX_CHOICES[gender_raw]
                 actor.movie_ids = row['id']
                 if each_actor['profile_path']:
                     actor.pic = each_actor['profile_path']
             actor.save()
         # import Directors, Writers from crew
         crews_raw = row['crew']
         crews_list = eval(crews_raw)
         # get only 1 writer
         flag_one_writer = False
         # get only 1 director
         flag_one_director = False
         for crew in crews_list:
             # import Director
             if flag_one_director == False and crew['job'] == 'Director':
                 try:
                     director = Director.objects.get(director_id=crew['id'])
                     director.movie_ids = director.movie_ids + ',' + row[
                         'id']
                 except:
                     director = Director()
                     director.director_id = crew['id']
                     director.name = crew['name']
                     gender_raw = crew['gender']
                     director.gender = SEX_CHOICES[gender_raw]
                     director.movie_ids = row['id']
                 director.save()
                 flag_one_director = True
             # import Writer
             elif flag_one_writer == False and crew[
                     'department'] == 'Writing':
                 try:
                     writer = Writer.objects.get(writer_id=crew['id'])
                     writer.movie_ids = writer.movie_ids + ',' + row['id']
                 except:
                     writer = Writer()
                     writer.writer_id = crew['id']
                     writer.name = crew['name']
                     gender_raw = crew['gender']
                     writer.gender = SEX_CHOICES[gender_raw]
                     writer.movie_ids = row['id']
                 writer.save()
                 flag_one_writer = True
             if flag_one_writer == True and flag_one_director == True:
                 break
コード例 #7
0
 def test_actor_has_str_repr(self):
     actor = Actor(name="Leonardo DiCaprio")
     self.assertEqual(actor.name, str(actor))
コード例 #8
0
ファイル: test_models.py プロジェクト: lype86/cine
 def setUp(self):
     self.actor = Actor(
         name='Fulano',
         country='Brasil',
     )
     self.actor.save()