Skip to content

Instantly share code, notes, and snippets.

@bwarren2
Created September 24, 2014 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwarren2/f0b296fff71b78c42488 to your computer and use it in GitHub Desktop.
Save bwarren2/f0b296fff71b78c42488 to your computer and use it in GitHub Desktop.
Model_mommy seq errors
#script.py
from heroes.mommy_recipes import make_hero
make_hero(steam_id=1)
# mommy_recipes.py
from model_mommy.recipe import Recipe, seq, foreign_key
from model_mommy import mommy
from heroes.models import Hero
my_hero = Recipe(
Hero,
visible=True,
# name=seq('Hero'),
# steam_id=seq(1),
)
def make_hero(steam_id=None):
if steam_id is not None:
hero = mommy.make_recipe('heroes.my_hero')
else:
hero = mommy.make_recipe('heroes.my_hero')
return hero
# models.py
class Hero(models.Model):
name = models.CharField(
max_length=200,
help_text="In-game name."
)
steam_id = models.PositiveIntegerField(
unique=True,
)
# uncommenting the sequences,
# stacktrace
Traceback (most recent call last):
File "convenience files/kernprof test.py", line 3, in <module>
make_hero(steam_id=1)
File "/home/me/Projects/proj/proj/proj/heroes/mommy_recipes.py", line 63, in make_hero
hero = mommy.make_recipe('heroes.my_hero')
File "/home/me/.virtualenvs/venv/local/lib/python2.7/site-packages/model_mommy/mommy.py", line 86, in make_recipe
return _recipe(mommy_recipe_name).make(_quantity=_quantity, **new_attrs)
File "/home/me/.virtualenvs/venv/local/lib/python2.7/site-packages/model_mommy/recipe.py", line 43, in make
return mommy.make(self.model, **self._mapping(attrs))
File "/home/me/.virtualenvs/venv/local/lib/python2.7/site-packages/model_mommy/recipe.py", line 28, in _mapping
mapping[k] = self._iterator_backups[k][1]
KeyError: 'steam_id'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment