model-bakers / model-bakers/model_bakery

Can't extend receipt through reverse name of OneToOne field.

Open
#97 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
1k
Forks
107
Avg merge
13h 27m
Merged PRs (30d)
12

Description

This is available for foreign_key fields and reverse many2many fields(related), but I haven't found (maybe badly searched) how to do it for backward one-to-one field access. I mean that:

# models.py
from django.db import models

class Person(models.Model):
    name = models.CharField(max_length=256)

class RelatedNamesModel(models.Model):
    name = models.CharField(max_length=256)
    one_to_one = models.OneToOneField(
        Person, related_name="one_related", on_delete=models.CASCADE
    )

# reciepts.py
from model_bakery.recipe import Recipe
from models import Person, RelatedNamesModel

person = Recipe(Person)
name = Recipe(RelatedNamesModel)
person_with_names = person.extend(one_related=name)  # it's not work

Versions

Python: 3.8.3
Django: 3.0.8
Model Bakery: 1.1.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the relationship shown in models.py using the recipe setup in reciepts.py, focusing on the reverse one-to-one name one_related. Verify the intended behavior by checking whether person.extend(one_related=name) creates the related object and preserves the relationship; the issue provides no test file or implementation entry point.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.