Giter Club home page Giter Club logo

factoryboy_oto_demo's Introduction

FactoryBoy One-to-One Demo (a.k.a. factoryboy_oto_demo)

I've played around with how to to one-to-one Factory creation with FactoryBoy a number of times. With the latest version of FactoryBoy (2.9.2), I got tired of chasing down "how I did it in the past", and decided to build a demo repo.

Note, this demo is current for factory-boy==v2.9.2. It should work for every 2.9.x release, but may need to be modified for future releases.

Types

There are two types of one-to-one mappings exposed in this demo. I'll call the first version Simple One-to-One. This is where a ModelA has a PK that points at ModelB, and vice-versa.

The second version (does it have a name?, we'll call it Complex One-to-One) is a joint form of One-to-One mapping and One-to-Many mapping. I.e. ModelA has a PK to ModelB, while ModelB is mapped to a particular ModelA.

Example

Simple One-to-One

In this repository, I've got a Musician with a Profile. They point at each other. That's it. In the SQL world, sometimes it's handy to point backwards. That's all.

Complex One-to-One

In this repository, I've got a Musician who has composed Songs. On its face this is a One-to-Many mapping. However, in this example, a musician also has a best_song and a worst_song. Suddenly there are two One-to-One mappings.

Testing

Download this repository, create a virtualenv, install the package, and run pytest.

git clone https://github.com/dfee/factoryboy_oto_demo
cd factoryboy_oto_demo
python -m venv env
source env/bin/activate
pip install -e .
pytest

factoryboy_oto_demo's People

Contributors

dfee avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.