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

added after creating to factories #304

Merged
merged 1 commit into from
Jan 9, 2021
Merged

added after creating to factories #304

merged 1 commit into from
Jan 9, 2021

Conversation

josephmancuso
Copy link
Member

@josephmancuso josephmancuso commented Jan 9, 2021

Closes #252

This PR adds the ability to add an after_creating method to the factory class.

You can now do something like this:

def add_order(self, faker):
    return {
        "subtotal": faker.amount(),
        "tax": faker.amount(),
    }

def after_order(self, model, faker):
    model.grand_total = model.subtotal + model.tax

factory.register(User, add_order)
factory.after_creating(User, after_order)

Now the order model will be passed to this after_order callback when you create the order class:

order = factory(Order).create()
order.grand_total #== now set because it was passed to the `after_order` method

@josephmancuso josephmancuso self-assigned this Jan 9, 2021
@josephmancuso josephmancuso merged commit e9e08c1 into 1.0 Jan 9, 2021
@josephmancuso josephmancuso deleted the feature/252 branch January 23, 2021 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add after_creating to factory class
1 participant