Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs #16

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ This is how you could define a factory for `Django`_'s built-in ``User`` model.
FileSystemStorage,
SubFactory,
pre_save,
trait,
)

STORAGE = FileSystemStorage(root_path=settings.MEDIA_ROOT, rel_path="tmp")
Expand All @@ -230,6 +231,12 @@ This is how you could define a factory for `Django`_'s built-in ``User`` model.
model = User
get_or_create = ("username",)

@trait
def is_admin_user(self, instance: User) -> None:
instance.is_superuser = True
instance.is_staff = True
instance.is_active = True

@pre_save
def __set_password(instance):
instance.set_password("test")
Expand All @@ -238,9 +245,15 @@ And this is how you could use it:

.. code-block:: python

# Create just one user
user = UserFactory()

# Create 5 users
users = UserFactory.create_batch(5)

# Create a user using `is_admin_user` trait
user = UserFactory(is_admin_user=True)

Tests
=====

Expand Down