Example #1
0
    def handle(self, *args, **options):
        tags = [
                'javascript', 'java', 'c#', 'php', 'android', 'jquery', 'python',
                'html', 'css', 'c++', 'ios', 'mysql', 'objective-c', 'sql', 'asp.net',
                'ruby-on-rails', 'iphone', 'angularjs', 'regexp'
                ]

        colors = Tag.COLORS

        for tag in tags:
            if len(Tag.objects.filter(title=tag)) == 0:
                t = Tag()

                t.title = tag
                t.color = choice(colors)[0]
                t.save()

        number = int(options['number'])

        tags = Tag.objects.all()

        # for tmp in tags:
        #     self.stdout.write(tmp.title)        

        for question in Question.objects.all():
            self.stdout.write('question [%d]' % question.id)
            if len(question.tags.all()) < number:
                for i in range(number - len(question.tags.all())):
                    tag = choice(tags)
                    if tag not in question.tags.all():
                        question.tags.add(tag)
Example #2
0
 def create_tags(self):
     faker = Faker()
     random_tags = faker.words(nb=10, ext_word_list=None)
     for tag in random_tags:
         t = Tag()
         t.title = tag
         t.save()