Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6927293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:02:01+00:00 2026-05-27T11:02:01+00:00

Referring to django-autofixture documentation , I wrote the following code (edited for terseness): def

  • 0

Referring to django-autofixture documentation, I wrote the following code (edited for terseness):

    def random_state_generator(self, states=None): 
        import random
        if not states: 
            states = "waiting|email|post|einv".split('|')
        while 1: 
            yield random.choice(states)

…

   rsg = self.random_state_generator()
   self.create_test_foo(10, values={'state': rsg})

…

    field_values = dict(field_values.items() + values.items())
    foo_fixture = AutoFixture(FooClass, overwrite_defaults=True, 
                              generate_fk=generate_fk_values,
                              field_values=field_values)
    bunch_of_stuff = foo_fixture.create(foo_count)

Okay,
now when I have the DB all set up, and I filter myself a list of stuff,
and go

for foo in bunch_of_stuff: print (foo.state)

instead of getting the expected random state string, I get the following output:

generator object random_state_generator at 0x242c640>

which is not what I’d expect based on the documentation, specifically

field_values: A dictionary with field names of model as keys. Values may be static values that are assigned to the field, a Generator instance that generates a value on the fly or a callable which takes no arguments and returns the wanted value.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:02:02+00:00Added an answer on May 27, 2026 at 11:02 am

    Okay, the field_values takes a class instance from autofixture.generators, so all I had to do was:
    generate the list of states;

    from autofixture.generators import ChoicesGenerator
    states = "waiting|email|post|einv".split('|')
    rsg = ChoicesGenerator(values=states)
    self.create_test_foo(10, values={'state': rsg})
    

    the misunderstanding rose from confusing autofixture’s generators with generic python generators.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a snippet of code like this in a Django application def update_account(user_account,add_widget_count):
Consider the following: >>> from django.conf import settings >>> import os >>> settings.VIRTUAL_ENV 'C:/Users/Marcin/Documents/oneclickcos'
from django.contrib.auth.models import User u = User.objects.get(username='test') user.password u'sha1$c6755$66fc32b05c2be8acc9f75eac3d87d3a88f513802 Is reversing this password encryption
I am doing a Django tutorial on Templates. I am currently at this code:
I have a simple view in Django: @render_to('episode_list.html') def list_episodes(request, season): query = Episode.objects.filter(season=season)
Referring to the code below, is there a way to bind the test 2
Referring to the Netfilter hook code at this page The port to be checked
I've got a Model in Django, example code below (not my actual code): class
Referring to the following tutorial: ADO.NET Entity Framework Tutorial and Basics I am trying
Using django-contact-form , I have overridden the form class: from contact_form.forms import ContactForm from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.