my-django-seed


Namemy-django-seed JSON
Version 1.1.9.4 PyPI version JSON
download
home_page
SummarySeed your Django project with fake data, this is a fork of the original django_seed to support 2.7 with small changes.
upload_time2023-02-08 12:45:05
maintainer
docs_urlNone
authorMoti shakuri
requires_python
licenseMIT
keywords faker fixtures data test django seed
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            |seed-logo|

===========

*Django-seed* uses the `faker`_ library to generate test data for your Django models. This has been "hard-forked" from `django_faker`_ in order to support newer versions of Python and Django

Django-seed allows you to write code to generate models, and seed your database with one simple ``manage.py`` command!

---------------

|python| |pypi| |actions| |coveralls| |license| |downloads|

---------------

* `Installation`_
* `Configuration`_
* `Usage`_
* `Using with command`_
* `Using with code`_
* `Tests`_
* `License`_

---------------

------------
Installation
------------

To install django-seed, use pip::

    pip install django-seed

Or to install from source::

    python setup.py install


-------------
Configuration
-------------

Add it to your installed apps in ``settings.py``::

    INSTALLED_APPS = (
        ...
        'django_seed',
    )

-----
Usage
-----

**Note**: When seeding models with Foreign Keys, you need to make sure that those models are seeded first. For example, if a model in app `A` has a foreign key to a model in app `B`, you must seed app `B` first.

Using with command
------------------

With *django-seed*, you can seed your database with test data from the command line using the ``manage.py seed`` command.

Ex: Seed 15 of each model for the app ``api``:

.. code-block:: bash

    $ python manage.py seed api --number=15

That's it! Now you have 15 of each model seeded into your database.

Should you need, you can also specify what value a particular field should have. For example, if you want to seed 15 of ``MyModel``, but you need ``my_field`` to be the same on all of them, you can do it like this: 

.. code-block:: bash

    $ python manage.py seed api --number=15 --seeder "MyModel.my_field" "1.1.1.1"
    
This is the command equivalent to doing it in Python:

.. code-block:: python

    seeder.add_entity(MyModel, 10, {
        'my_field': '1.1.1.1',
    })

Using with code
----------------

*django-seed* provides methods to easily seed test databases for your Django models. To seed your database with Model instances, import ``Seed``, get a ``seeder`` instance, and use the `add_entity` method.

Ex: seeding 5 ``Game`` and 10 ``Player`` objects:

.. code-block:: python

    from django_seed import Seed

    seeder = Seed.seeder()

    from myapp.models import Game, Player
    seeder.add_entity(Game, 5)
    seeder.add_entity(Player, 10)

    inserted_pks = seeder.execute()

The seeder uses the name and column type to populate the Model with relevant data. If django-seed misinterprets a column name or column type and *AttributeError(field)* is thrown, you can still specify a custom function to be used for populating a particular column, by adding a third argument to the ``add_entity()`` method:

.. code-block:: python

    seeder.add_entity(Player, 10, {
        'score':    lambda x: random.randint(0, 1000),
        'nickname': lambda x: seeder.faker.email(),
    })
    seeder.execute()

Django-seed does not populate auto-incremented primary keys, instead ``seeder.execute()`` returns the list of inserted PKs, indexed by class:

.. code-block:: python

    print inserted_pks
    {
        <class 'faker.django.tests.Player'>: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
        <class 'faker.django.tests.Game'>: [1, 2, 3, 4, 5]
    }

You may specify a different locale by passing it in the constructor of the seeder. Defaults to `settings.LANGUAGE_CODE`

.. code-block:: python

    seeder = Seed.seeder(locale='sv_SE')
    seeder.faker.city()  # 'Västerås'


Localization
------------

``Seed.seeder()`` can take a locale as an argument, to return localized data.
You can find all possible locales in `faker's documentation`_

In order to apply localization, do the next:

.. code-block:: python

    seeder = Seed.seeder('it_IT')

-----
Tests
-----

To run django tests in a django environment, first make sure you have the packages from `requirement-test.txt` installed, then run the following:

.. code-block:: bash

    $ python runtests.py

or if you have ``django_seed`` in INSTALLED_APPS:

.. code-block:: bash

    $ python manage.py test django_seed

-------
License
-------

MIT. See `LICENSE`_ for more details.


.. _faker: https://www.github.com/joke2k/faker/
.. _django_faker: https://www.github.com/joke2k/django-faker/
.. _faker's documentation: https://faker.readthedocs.io/en/latest/locales.html
.. _LICENSE: https://github.com/Brobin/django-seed/blob/master/LICENSE

.. |pypi| image:: https://img.shields.io/pypi/v/django-seed.svg?style=flat-square
    :target: https://pypi.python.org/pypi/django-seed
    :alt: pypi

.. |actions| image:: https://github.com/Brobin/django-seed/workflows/Test/badge.svg
    :target: https://github.com/Brobin/django-seed
    :alt: Actions Build
    
.. |coveralls| image:: https://img.shields.io/coveralls/Brobin/django-seed.svg?style=flat-square
    :target: https://coveralls.io/r/Brobin/django-seed
    :alt: coverage

.. |license| image:: https://img.shields.io/github/license/Brobin/django-seed.svg?style=flat-square
    :target: https://github.com/Brobin/django-seed/blob/master/LICENSE
    :alt: MIT License

.. |python| image:: https://img.shields.io/pypi/pyversions/django-seed.svg?style=flat-square
    :target: https://pypi.python.org/pypi/django-seed
    :alt: Python 3.x

.. |seed-logo| image:: assets/django_seed.png
    :alt: Django Seed

.. |downloads| image:: https://pepy.tech/badge/django-seed
    :target: https://pepy.tech/project/django-seed
    :alt: downloads
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "my-django-seed",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "faker fixtures data test django seed",
    "author": "Moti shakuri",
    "author_email": "motishaku@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ac/31/06830b940c4da7834d2d31114ce0ace1b022b3f60fe0db7bfffe414592cc/my_django_seed-1.1.9.4.tar.gz",
    "platform": null,
    "description": "|seed-logo|\n\n===========\n\n*Django-seed* uses the `faker`_ library to generate test data for your Django models. This has been \"hard-forked\" from `django_faker`_ in order to support newer versions of Python and Django\n\nDjango-seed allows you to write code to generate models, and seed your database with one simple ``manage.py`` command!\n\n---------------\n\n|python| |pypi| |actions| |coveralls| |license| |downloads|\n\n---------------\n\n* `Installation`_\n* `Configuration`_\n* `Usage`_\n* `Using with command`_\n* `Using with code`_\n* `Tests`_\n* `License`_\n\n---------------\n\n------------\nInstallation\n------------\n\nTo install django-seed, use pip::\n\n    pip install django-seed\n\nOr to install from source::\n\n    python setup.py install\n\n\n-------------\nConfiguration\n-------------\n\nAdd it to your installed apps in ``settings.py``::\n\n    INSTALLED_APPS = (\n        ...\n        'django_seed',\n    )\n\n-----\nUsage\n-----\n\n**Note**: When seeding models with Foreign Keys, you need to make sure that those models are seeded first. For example, if a model in app `A` has a foreign key to a model in app `B`, you must seed app `B` first.\n\nUsing with command\n------------------\n\nWith *django-seed*, you can seed your database with test data from the command line using the ``manage.py seed`` command.\n\nEx: Seed 15 of each model for the app ``api``:\n\n.. code-block:: bash\n\n    $ python manage.py seed api --number=15\n\nThat's it! Now you have 15 of each model seeded into your database.\n\nShould you need, you can also specify what value a particular field should have. For example, if you want to seed 15 of ``MyModel``, but you need ``my_field`` to be the same on all of them, you can do it like this: \n\n.. code-block:: bash\n\n    $ python manage.py seed api --number=15 --seeder \"MyModel.my_field\" \"1.1.1.1\"\n    \nThis is the command equivalent to doing it in Python:\n\n.. code-block:: python\n\n    seeder.add_entity(MyModel, 10, {\n        'my_field': '1.1.1.1',\n    })\n\nUsing with code\n----------------\n\n*django-seed* provides methods to easily seed test databases for your Django models. To seed your database with Model instances, import ``Seed``, get a ``seeder`` instance, and use the `add_entity` method.\n\nEx: seeding 5 ``Game`` and 10 ``Player`` objects:\n\n.. code-block:: python\n\n    from django_seed import Seed\n\n    seeder = Seed.seeder()\n\n    from myapp.models import Game, Player\n    seeder.add_entity(Game, 5)\n    seeder.add_entity(Player, 10)\n\n    inserted_pks = seeder.execute()\n\nThe seeder uses the name and column type to populate the Model with relevant data. If django-seed misinterprets a column name or column type and *AttributeError(field)* is thrown, you can still specify a custom function to be used for populating a particular column, by adding a third argument to the ``add_entity()`` method:\n\n.. code-block:: python\n\n    seeder.add_entity(Player, 10, {\n        'score':    lambda x: random.randint(0, 1000),\n        'nickname': lambda x: seeder.faker.email(),\n    })\n    seeder.execute()\n\nDjango-seed does not populate auto-incremented primary keys, instead ``seeder.execute()`` returns the list of inserted PKs, indexed by class:\n\n.. code-block:: python\n\n    print inserted_pks\n    {\n        <class 'faker.django.tests.Player'>: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n        <class 'faker.django.tests.Game'>: [1, 2, 3, 4, 5]\n    }\n\nYou may specify a different locale by passing it in the constructor of the seeder. Defaults to `settings.LANGUAGE_CODE`\n\n.. code-block:: python\n\n    seeder = Seed.seeder(locale='sv_SE')\n    seeder.faker.city()  # 'V\u00e4ster\u00e5s'\n\n\nLocalization\n------------\n\n``Seed.seeder()`` can take a locale as an argument, to return localized data.\nYou can find all possible locales in `faker's documentation`_\n\nIn order to apply localization, do the next:\n\n.. code-block:: python\n\n    seeder = Seed.seeder('it_IT')\n\n-----\nTests\n-----\n\nTo run django tests in a django environment, first make sure you have the packages from `requirement-test.txt` installed, then run the following:\n\n.. code-block:: bash\n\n    $ python runtests.py\n\nor if you have ``django_seed`` in INSTALLED_APPS:\n\n.. code-block:: bash\n\n    $ python manage.py test django_seed\n\n-------\nLicense\n-------\n\nMIT. See `LICENSE`_ for more details.\n\n\n.. _faker: https://www.github.com/joke2k/faker/\n.. _django_faker: https://www.github.com/joke2k/django-faker/\n.. _faker's documentation: https://faker.readthedocs.io/en/latest/locales.html\n.. _LICENSE: https://github.com/Brobin/django-seed/blob/master/LICENSE\n\n.. |pypi| image:: https://img.shields.io/pypi/v/django-seed.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/django-seed\n    :alt: pypi\n\n.. |actions| image:: https://github.com/Brobin/django-seed/workflows/Test/badge.svg\n    :target: https://github.com/Brobin/django-seed\n    :alt: Actions Build\n    \n.. |coveralls| image:: https://img.shields.io/coveralls/Brobin/django-seed.svg?style=flat-square\n    :target: https://coveralls.io/r/Brobin/django-seed\n    :alt: coverage\n\n.. |license| image:: https://img.shields.io/github/license/Brobin/django-seed.svg?style=flat-square\n    :target: https://github.com/Brobin/django-seed/blob/master/LICENSE\n    :alt: MIT License\n\n.. |python| image:: https://img.shields.io/pypi/pyversions/django-seed.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/django-seed\n    :alt: Python 3.x\n\n.. |seed-logo| image:: assets/django_seed.png\n    :alt: Django Seed\n\n.. |downloads| image:: https://pepy.tech/badge/django-seed\n    :target: https://pepy.tech/project/django-seed\n    :alt: downloads",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Seed your Django project with fake data, this is a fork of the original django_seed to support 2.7 with small changes.",
    "version": "1.1.9.4",
    "split_keywords": [
        "faker",
        "fixtures",
        "data",
        "test",
        "django",
        "seed"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ac3106830b940c4da7834d2d31114ce0ace1b022b3f60fe0db7bfffe414592cc",
                "md5": "4b4a2bd01b30d3c9f2630acfb43c091b",
                "sha256": "75d27647f818c2c7e1177930683a114ad6adbbd91801739c0c1d9613ca0e2bab"
            },
            "downloads": -1,
            "filename": "my_django_seed-1.1.9.4.tar.gz",
            "has_sig": false,
            "md5_digest": "4b4a2bd01b30d3c9f2630acfb43c091b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 13308,
            "upload_time": "2023-02-08T12:45:05",
            "upload_time_iso_8601": "2023-02-08T12:45:05.791448Z",
            "url": "https://files.pythonhosted.org/packages/ac/31/06830b940c4da7834d2d31114ce0ace1b022b3f60fe0db7bfffe414592cc/my_django_seed-1.1.9.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-08 12:45:05",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "my-django-seed"
}
        
Elapsed time: 0.04409s