Usage
from tortoise import Model, fields
from tortoise_factory import model_factory
class User(Model):
id = fields.IntField(primary_key=True)
first_name = fields.CharField(max_length=100)
last_name = fields.CharField(max_length=100)
email = fields.CharField(max_length=200)
class Product(Model):
id = fields.IntField(primary_key=True)
name = fields.CharField(max_length=200)
description = fields.TextField(null=True, default=None)
price = fields.FloatField()
created_by = fields.ForeignKeyField(
"models.User",
on_delete=fields.CASCADE,
related_name="products",
)
def __str__(self) -> str:
return self.name
Generalities
All returned models are saved in db, meaning they will all have a .id value, the same is true for any ForeignKeyField
Random values
To get a simple random product:
product = await model_factory(Product)
the created_by will be created automaticaly since it cannot be None, when possible, the factory will put None into optional fields.
Specify some fields
product = await model_factory(Product, name="something", created_by__name="Bob")
we use __ to go throught relations
Fill optional values
product = await model_factory(Product, _optionals=["description"])
now you will have a product.description wich won't be None
Metadata
Release files for tortoise-factory 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tortoise_factory-0.1.0.tar.gz | 3.6 kB | Without provenance | Details for tortoise_factory-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tortoise_factory-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tortoise_factory-0.1.0-py3-none-any.whl |
Total release size: 7.9 kB
Release files / tortoise_factory-0.1.0.tar.gz
| Download URL | tortoise_factory-0.1.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b351f8b8d9d3e4727e91e26af697b1b963cf64b660d51d9838fa6bda9580c428
|
|
BLAKE2b-256 checksum How to use checksums |
8beedba834b5fc25c2fb7f94c9674a9594673b029bc8dbdf1b85ffc95f3a71d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.6 Linux/6.10.8-arch1-1
|
Release files / tortoise_factory-0.1.0-py3-none-any.whl
| Download URL | tortoise_factory-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21c9727b2ba83e905a9453f40dd9b20d79041cefadcfca7b0d234583c5f6eb94
|
|
BLAKE2b-256 checksum How to use checksums |
6edfbdb5145086944dffc6e400926832474eed0b559c2fa8e2ba3efcd6f567bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.6 Linux/6.10.8-arch1-1
|
Security for tortoise-factory 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.