Permalink
Browse files

new module ForeignKey

  • Loading branch information...
Simon Bächler
Simon Bächler committed Mar 6, 2012
1 parent 99b0385 commit 9002066c5a6962bd432fae7090b4ba654bf4932d
Showing with 18 additions and 0 deletions.
  1. +18 −0 scaffolding/__init__.py
View
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import os
import random
+import gc
from scaffolding import library
from library.lorem_ipsum import LOREM_IPSUM
import urllib
@@ -109,3 +110,20 @@ def next(self):
url = self.backend.next()
temp_image = urllib.urlretrieve(url)
return os.path.basename(url), File(open(temp_image[0]))
+
+class ForeignKey(Tube):
+ """ Creates a foreign key assigning the queryset.
+ """
+ def __init__(self, queryset, chunksize=100, wrap=True, **kwargs):
+ super(ForeignKey, self).__init__(**kwargs)
+ self.queryset = queryset.order_by('pk')[:chunksize]
+ self.wrap = wrap
+ self.length = len(self.queryset)
+ self.i = 0
+
+ def next(self):
+ if self.i == (self.length-1):
+ self.i = 0
+ return self.queryset[0]
+ self.i += 1
+ return self.queryset[self.i]

0 comments on commit 9002066

Please sign in to comment.