Package: django-scaffolding
IntroductionDjango-Scaffolding creates pseudo-real-world placeholder data for your app.
Data can be any type like names, cities, images and instances of your models.
It’s not a mocking framework, it creates real django model instances.UsageAddscaffoldingto your INSTALLED_APPSCreate ascaffolds.pymodule within your app directory which contains the Scaffolding classes.Samplemodels.py:class Entry(models.Model):
    first_name = models.CharField('First Name', max_length=32)
    last_name = models.CharField('Last Name', max_length=32)
    comment = models.TextField('Comment', blank=True)
    image = models.ImageField(upload_to='uploads/%Y/%m/%d', blank=True, null=True)
    contest = models.ForeignKey(Contest)
    ...Samplescaffolds.py:import scaffolding
from scaffolding.library.flickr import FlickrInteresting

class EntryScaffold(object):
    first_name = scaffolding.FirstName(max_length=32)
    last_name = scaffolding.LastName(max_length=32)
    comment = scaffolding.OrBlank(scaffolding.LoremIpsum, paragraphs=1)
    contest = scaffolding.ForeignKey(queryset=Contest.objects.filter(name='testcontest'))
    image = scaffolding.RandomInternetImage(backend=FlickrInteresting)

    @classmethod
    finalize(cls, obj):
        # Just an example method
        obj.end_date = obj.start_date + datetime.timedelta(days=60)


scaffolding.register(Entry, EntryScaffold)Mind the syntax for ForeignKey fields. You can assign an integer to the field
but make sure the element with the corresponding key does exist.
Of course you can also assign an object to the FK field.To use the flickr library you need to have the Flickr API:http://stuvel.eu/flickrapiversion 1.4.5 installed.Run the management command to create the data:manage.py scaffold myapp.MyModel 20The number stands for the number of entries to be created.Using scaffolding in the interpreter or in viewsYou can try out the included classes or your own modules in the shell.
All classes are generators (called Tubes) that generate the values for the fields.
start ./manage.py shell:>>> from scaffolding import *
>>> r = RandInt(min=1, max=5)
>>> r.next()
[4]
>>> r.next()
[2]

>>> n = Name(gender='m')
>>> n.next()
[u'Ethan Schmid']
>>> n.next()
[u'Michael Schneider']Using finalize()If a Scaffold class contains afinalize(cls, obj)class method, the method is called
after the model is created and before it is saved. This makes it possible to
set properties which are dependent on field values.Included TubesNameGenerates a random name. <gender> can be ‘male’, ‘female’, ‘m’ or ‘f’.FirstName and LastNameGenerates only first or last name. Takes thegenderattribute as well.LoremIpsumGenerates a Lorem Ipsum Text. The number of paragraphs is defined in paragraphs.RandIntGenerates a random integer between min and max.ForeignKeyTakes a queryset and iterates through it. Assigns the
item asForeignKeyto the field. Wraps around if there
are not enough items.ForeignKeyOrNoneThe same for nullable ForeignKeys.splitis the weight for positives. 0.2 yields 80% None.RandomInternetImageCreates a random image for an ImageField using an internet source.
A Flickr ‘Daily Interesting images’ grabber is included.RandomDateCreates a random date betweenstartdateandenddate.startdateandenddatehave to bedatetime.dateinstances.RandomDatetimeCreates a random datetime instance betweenstartdateandenddate.startdateandenddatehave to bedatetime.datetimeinstances.
If a timezone is passed in the parametertimezone, the instance is timezone-aware.UsCityReturns a name of a US city and state. e.g. “New York, NY”.BookTitleCreates a book title.
This is a python implementation of theRandom Title Generator.URLCreates a linkable to URL from a list of about 10000 URLs.RandomEmailCreates a random email. Parameters arelengthanddomain.AlwaysTrueReturnsTrueAlwaysFalseReturnsFalseTrueOrFalseRandomly returns true or false.
You can set a ratio for true or false by specifying true or false:
e.g.false=3returns 3 times as many False than Trues.StaticValueTakes one argumentvalueand assigns it to the field.RandomValueTakes a list (not an iterable) as itslstargument and returns an
element from it.
You can use this for choice fields as well:[c[0] for c in MyModel.MYCHOICES]Every ValueTakes an iterable as itsvaluesargument and loops through them in order.OrNoneThis is a special tube that takes another tube as its first argument.
It assigns a value from the passed class or None. This is useful for nullable
fields. You can pass the arguments for the wrapped class as arguments to the
OrNone class. There is one additional argument:split. This defines a ratio
of useful to None. A ratio of 0.2 will give you 80% None.OrBlankThe same as OrNone, but uses a blank string instead of None.
Ideal for text fields that haveblank=True.UuidGenerates a unique alphanumeric id. Takes an optional parameterformatwhich
can be one ofuuid,hexorint. Default ishex.
If the format isuuidit generates a Uuid4 instance.ContribCrates a Custom Object. The backend class is the first parameter.
The backend class has to inherit from Tube:user = scaffolding.Contrib(FacebookTestUser, app_name='contest')FacebookTestUserCreates a Facebook User from the test users pool of the Facebook app.
If there aren’t enough test users new ones are automatically created.
This requires the django-facebook-graph API.https://github.com/feinheit/django-facebook-graphThe module is inexternal.facebook_graph.