1. Artur Barseghyan
  2. sirep

Commits

Artur Barseghyan  committed 7f3943c Draft

fix test data script

  • Participants
  • Parent commits 0570adf
  • Branches default

Comments (0)

Files changed (1)

File example/example/foo/management/commands/foo_create_test_data.py

View file
  • Ignore whitespace
 
 class Command(BaseCommand):
     def handle(self, *args, **options):
-        for index in xrange(100):
+        words = WORDS
+        for index in xrange(20):
             c = FooCategory()
-            c.name = unicode(WORDS[random.randint(0, len(WORDS) - 1)]).capitalize()
+            random_name = words[random.randint(0, len(words) - 1)]
+            c.name = unicode(random_name).capitalize()
             c.slug = slugify(c.name)
             try:
                 c.save()
+                words.remove(random_name)
             except Exception, e:
                 pass
 
         categories = FooCategory.objects.all()[:]
         users = User.objects.all()[:]
 
+        words = WORDS
         for index in xrange(100):
             i = FooItem()
-            i.title = unicode(WORDS[random.randint(0, len(WORDS) - 1)]).capitalize()
+            random_name = words[random.randint(0, len(words) - 1)]
+            i.title = unicode(random_name).capitalize()
             i.slug = slugify(i.title)
             i.body = unicode(SENTENCES[random.randint(0, len(SENTENCES) - 1)])
             i.date_published = radar.random_datetime()
 
             try:
                 i.save()
+                words.remove(random_name)
 
                 for index in xrange(random.randint(1, 4)):
                     for z in xrange(0, index):