Chris Lamb

django-auto-one-to-one

BlogProjectsAbout

View all my projects »

Automatically create and destroy child model instances.


Automatically create child model instances when a parent class is created.

For example, given the following model definition:

from django.db import models
from django_auto_one_to_one import AutoOneToOneModel

class Parent(models.Model):
    field_a = models.IntegerField(default=1)

class Child(AutoOneToOneModel(Parent)):
    field_b = models.IntegerField(default=2)

... creating a Parent instance automatically creates a related Child instance:

>>> p = Parent.objects.create()
>>> p.child
<Child: parent=assd>
>>> p.child.field_b
2

A PerUserData helper is provided for the common case of creating instances when a User instance is created.


If you are looking for a highly experienced full-stack Django developer with a track record of producing high-quality and maintaininable code, please get in touch.

You can install django-auto-one-to-one from PyPI:

$ pip install django-auto-one-to-one
… or by adding django-auto-one-to-one to your requirements.txt and re-running pip install -r requirements.txt.

You can browse the source tree, create or file bugs or download the code from Git:

$ git clone https://github.com/lamby/django-auto-one-to-one

django-auto-one-to-one is released under the MIT license.

View all my projects »