Skip to main content

Helper class for generate sampledata

Project description

http://kaleidos.net/static/img/badge.png https://travis-ci.org/kaleidos/django-sampledatahelper.png?branch=master https://coveralls.io/repos/kaleidos/django-sampledatahelper/badge.png?branch=master https://pypip.in/v/django-sampledatahelper/badge.png https://pypip.in/d/django-sampledatahelper/badge.png

Helper class to create django sample data.

Example

Sample data command for generate instances of MyModel:

from django.core.management.base import BaseCommand
from myapp.models import MyModel
from sampledatahelper.helper import SampleDataHelper

class Command(BaseCommand):
    args = ''
    help = 'Example data generator'
    sd = SampleDataHelper(seed=12345678901)

    def generate_mymodel_data(self, instances):
        for x in range(instances):
            instance = MyModel.objects.create(
                slug=self.sd.slug(2, 3),
                name=self.sd.name(2, 3)
                claim=self.sd.sentence(),
                description=self.sd.paragraph(),
                email=self.sd.email(),
                photo=self.sd.image(64, 64),
                is_active=self.sd.boolean(),
                birth_date=self.sd.past_date(),
                expected_death_date=self.sd.future_date(),
                my_related_object=self.sd.db_object(MyRelatedModel)
            )

    def handle(self, *args, **options):
        print "Generating MyModel data"
        self.generate_mymodel_data(5)

Documentation

Read the Docs: https://django-sample-data-helper.readthedocs.org/en/latest/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-sampledatahelper-0.1.tar.gz (11.0 kB view details)

Uploaded Source

File details

Details for the file django-sampledatahelper-0.1.tar.gz.

File metadata

File hashes

Hashes for django-sampledatahelper-0.1.tar.gz
Algorithm Hash digest
SHA256 f11da7ca85dfc3b937d00d0aea482908695164d02140c674927495c7eeb1d80e
MD5 019017fb06d4c59461aab87ccb6ff885
BLAKE2b-256 217c98ffc48831cd9d40342bce0f5fe9207740ebd8b02398ed725e5cc8cb55b8

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page