コード例 #1
0
ファイル: generate.py プロジェクト: rowbotman/web-service-tp
def generate_tags(n_tags):
    fake_generator = faker.Faker()
    for i in range(n_tags):
        while True:
            n_words = random.randint(1, 4)
            tag_name = ' '.join(fake_generator.word() for _ in range(n_words))
            if Tag.objects.filter(title=tag_name).first() is None:
                break
        tag = Tag(title=tag_name)
        tag.save()
        print(f"[{i+1}/{n_tags}] Saved tag {tag}")
コード例 #2
0
ファイル: create_data.py プロジェクト: eprokofyev/WebAskme
 def handle(self):
     for i in range(10):
         user = User.objects.create_user(username='******' + str(i),
                                         password='******' + str(i + 1))
         user.save()
     for i in range(10):
         profile = Profile(user=User.objects.get(username='******' + str(i)),
                           i,
                           date(2005 + i, i + 1, (i + 1) * 2))
         profile.save()
     tags = [
         'django', 'python', 'shell', 'user', 'android', 'net', 'c', 'java',
         'web', 'html'
     ]
     for i in tags:
         tag = Tag(title=i)
         tag.save()
     for i in range(10):
         q = Question(
             title=
             "Cannot to set datetime with input field. Always return DateTime.MinValue",
             text=
             "My programm are supposed to have date filtr and gives article with proper date. But when i input any date in my datetime field my values don't change and are always DateTime.MinValue. Idk why and how i can fix it.",
             is_published=True,
             rating=i,
             author=Profile.objects.get(id=i + 1),
             likes=Profile.objects.get(id=(i + 2) // 2),
             tags=Tag.objects.all()[:i])
     for i in range(10):
         ans = Answer(
             text="Nice question!",
             added_at=date(2019, i + 1, (i + 1) * 2),
             question=Question.objects.get(id=i + 1),
             author=Profile.objects.get(id=(i + 2) // 2),
         )
     for i in range(10):
         ans = Answer(
             text="I don't know!",
             added_at=date(2019, i + 2, i + 3),
             question=Question.objects.get(id=(i + 2) // 2),
             author=Profile.objects.get(id=(i + 3) // 2),
         )
コード例 #3
0
ファイル: create_data.py プロジェクト: eprokofyev/WebAskme
	def handle(sself, *args, **options):
		for i in range(10):
			try:
				user = User.objects.get(username='******'+str(i))
			except User.DoesNotExist:
				user = User.objects.create_user(username='******' + str(i), password='******' + str(i + 1))
				user.is_superuser=False
				user.is_staff=False
				user.save()

		for i in range(10):
			try:
				profile = Profile.objects.get(user=User.objects.get(username='******' + str(i)))
			except Profile.DoesNotExist:
				profile = Profile(user=User.objects.get(username='******' + str(i)), rating=i, birthday=date(2005 + i, i + 1, (i + 1) * 2))
				profile.save()

		tags = ['django', 'python', 'shell', 'user', 'android', 'net', 'c', 'java', 'web', 'html']
		for i in tags:
			try:
				tag = Tag.objects.get(title=i)
			except Tag.DoesNotExist:	
				tag = Tag(title=i)
				tag.save()

		for i in range(10):
			try:
				q = Question.objects.get(title="Cannot to set datetime with input field. Always return DateTime.MinValue" + str(i), 
				text= str(i) + "My programm are supposed to have date filtr and gives article with proper date. But when i input any date in my datetime field my values don't change and are always DateTime.MinValue. Idk why and how i can fix it.",
				is_published=True,
				author=Profile.objects.get(id=i + 1),
				)
			except Question.DoesNotExist:
				q = Question(title="Cannot to set datetime with input field. Always return DateTime.MinValue" + str(i), 
					text=str(i) +"My programm are supposed to have date filtr and gives article with proper date. But when i input any date in my datetime field my values don't change and are always DateTime.MinValue. Idk why and how i can fix it.",
					date_published = datetime.now(),
					is_published=True,
					rating=i,
					author=Profile.objects.get(id=i + 1),
					#likes=likes.set(Profile.objects.get(id=(i + 2)//2)),
					#tags=Tag.objects.get(id=i+1)
					)
				#q.likes.set(Profile.objects.get(id=(i + 2)//2))
				#q.tags.set(Tag.objects.get(id=i+1))
				q.save()
				q.likes.add(Profile.objects.get(id=(i + 2)//2))
				q.tags.add(Tag.objects.get(id=i+1))

		for i in range(10):
			try:
				ans = Answer.objects.get(text="Nice question!",
				added_at = date(2019, i + 1, (i + 1) * 2),
				question=Question.objects.get(id=i + 1),
				author=Profile.objects.get(id=(i + 2)//2),
				)
			except Answer.DoesNotExist:
				ans = Answer(text="Nice question!",
					added_at = date(2019, i + 1, (i + 1) * 2),
					question=Question.objects.get(id=i + 1),
					author=Profile.objects.get(id=(i + 2)//2),
					)
				ans.save()

		for i in range(10):
			try:
				ans = Answer.objects.get(text="I don't know!",
				added_at = date(2019, i + 2, i + 3),
				question=Question.objects.get(id=(i+2)//2),
				author=Profile.objects.get(id=(i+3)//2),
				)
			except Answer.DoesNotExist:
				ans = Answer(text="I don't know!",
					added_at = date(2019, i + 2, i + 3),
					question=Question.objects.get(id=(i+2)//2),
					author=Profile.objects.get(id=(i+3)//2),
					)
				ans.save()
コード例 #4
0
 def handle(self, *args, **options):
     for tag in options['arg']:
         name = Tag(title=tag)
         name.save()