예제 #1
0
def import_data():
    # Initial Imports
    from django.contrib.auth.models import User

    # Processing model: posts.models.Post

    from posts.models import Post

    posts_post_1 = Post()
    posts_post_1.author =  importer.locate_object(User, "id", User, "id", 1, {'id': 1, 'password': '******', 'last_login': datetime.datetime(2018, 11, 27, 6, 31, 56, 449061, tzinfo=<UTC>), 'is_superuser': True, 'username': '******', 'first_name': '', 'last_name': '', 'email': '*****@*****.**', 'is_staff': True, 'is_active': True, 'date_joined': datetime.datetime(2018, 11, 27, 6, 31, 35, 527568, tzinfo=<UTC>)} )
    posts_post_1.link = 'https://stackoverflow.com/questions/3330435/is-there-an-sqlite-equivalent-to-mysqls-describe-table'
    posts_post_1.title = 'Initial Data'
    posts_post_1.description = 'Cool Description'
    posts_post_1 = importer.save_or_locate(posts_post_1)

    posts_post_2 = Post()
    posts_post_2.author =  importer.locate_object(User, "id", User, "id", 1, {'id': 1, 'password': '******', 'last_login': datetime.datetime(2018, 11, 27, 6, 31, 56, 449061, tzinfo=<UTC>), 'is_superuser': True, 'username': '******', 'first_name': '', 'last_name': '', 'email': '*****@*****.**', 'is_staff': True, 'is_active': True, 'date_joined': datetime.datetime(2018, 11, 27, 6, 31, 35, 527568, tzinfo=<UTC>)} )
    posts_post_2.link = 'https://simpleisbetterthancomplex.com/tutorial/2016/07/26/how-to-reset-migrations.html'
    posts_post_2.title = 'Reset Generator'
    posts_post_2.description = 'https://simpleisbetterthancomplex.com/tutorial/2016/07/26/how-to-reset-migrations.html'
    posts_post_2 = importer.save_or_locate(posts_post_2)

    # Processing model: posts.models.Vote

    from posts.models import Vote

    posts_vote_1 = Vote()
    posts_vote_1.voter =  importer.locate_object(User, "id", User, "id", 1, {'id': 1, 'password': '******', 'last_login': datetime.datetime(2018, 11, 27, 6, 31, 56, 449061, tzinfo=<UTC>), 'is_superuser': True, 'username': '******', 'first_name': '', 'last_name': '', 'email': '*****@*****.**', 'is_staff': True, 'is_active': True, 'date_joined': datetime.datetime(2018, 11, 27, 6, 31, 35, 527568, tzinfo=<UTC>)} )
    posts_vote_1.post = posts_post_1
    posts_vote_1.liked = True
    posts_vote_1 = importer.save_or_locate(posts_vote_1)

    posts_vote_2 = Vote()
    posts_vote_2.voter =  importer.locate_object(User, "id", User, "id", 2, {'id': 2, 'password': '******', 'last_login': None, 'is_superuser': False, 'username': '******', 'first_name': '', 'last_name': '', 'email': '', 'is_staff': False, 'is_active': True, 'date_joined': datetime.datetime(2018, 11, 27, 6, 35, 12, 746625, tzinfo=<UTC>)} )
    posts_vote_2.post = posts_post_1
    posts_vote_2.liked = True
    posts_vote_2 = importer.save_or_locate(posts_vote_2)

    # Processing model: posts.models.Comment

    from posts.models import Comment

    posts_comment_1 = Comment()
    posts_comment_1.description = 'My Cool Comment on Post 1 yeh.'
    posts_comment_1.author =  importer.locate_object(User, "id", User, "id", 1, {'id': 1, 'password': '******', 'last_login': datetime.datetime(2018, 11, 27, 6, 31, 56, 449061, tzinfo=<UTC>), 'is_superuser': True, 'username': '******', 'first_name': '', 'last_name': '', 'email': '*****@*****.**', 'is_staff': True, 'is_active': True, 'date_joined': datetime.datetime(2018, 11, 27, 6, 31, 35, 527568, tzinfo=<UTC>)} )
    posts_comment_1.post = posts_post_1
    posts_comment_1 = importer.save_or_locate(posts_comment_1)
예제 #2
0
 def create(self, validated_data):
     post = Post(
         title=validated_data['title'],
         author_name=validated_data['author_name'],
     )
     post.save()
     post.link = f'http://127.0.0.1:8000/posts/{post.pk}'
     post.save()
     return post
예제 #3
0
def save(country_data, country_code):
    print(f"Saving {country_code} data to DB...")
    for idx, row in enumerate(country_data):
        if (idx > 0):
            post_data = row.split(',')
            post = Post()
            post.title = post_data[2].replace('"', '')
            post.link = post_data[0].replace('"', '')
            post.description = post_data[1].replace('"', '')
            post.source = 'YOUTUBE'

            post.save()