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

  • Home
  • SEARCH
  • 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 9217211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:35:20+00:00 2026-06-18T02:35:20+00:00

I am using Factory Boy in a Django project and I need to access

  • 0

I am using Factory Boy in a Django project and I need to access class properties, defined in the class, in the corresponding factory.

My test case has something along the lines of:

from django.test.testcases import TransactionTestCase
from app.tests.factories import SomeModelFactory

class MyTestCase(TransactionTestCase):   
    def test_something(self):
        ...
        SomeModelFactory.create(
            data_type=SomeModelFactory.FACTORY_FOR.TYPE_STRING)
        ...

My class, as you may guess, has the corresponding constant in the right spot.

class SomeModel(models.Model):
  TYPE_STRING = 2
  ...

and the corresponding factory is defined as it should be

class SomeModelFactory(factory.Factory):
  FACTORY_FOR = SomeModel
  ...

The test case fails saying that FACTORY_FOR is not there. So, I think the metaclass is hidding that somewhere. Ideally, I would like to minimise the need to import the model directly if I am using the factory.

  • 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-06-18T02:35:21+00:00Added an answer on June 18, 2026 at 2:35 am

    SomeModelFactory._associated_class should be what you are looking for…

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

Sidebar

Related Questions

I'm trying to create a frame VCL inside my project using factory pattern something
I'm using the javax.xml.transform.Transformer class to perform some XSLT translations, like so: TransformerFactory factory
When using factory girl and RSpec to test my controller, I'm getting the error:
I am using Factory pattern to create .NET objects of a class. I also
In my program, some objects need other objects (dependency), and I'm using Factory as
Just started using factory girl. If one has to save a factory into the
I'm working on a rails project using, cucumber, capybara and factory girl, and recently
I have a Django (v1.4, using Postgresql) project which I've written a bunch of
I am using Factory Girl to create two instances in my model/unit test for
I'm using modelformset factory to generate formset from model fields. Here i want to

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.