0

I wanted to know if in the tests it is possible to somehow create an "artificial" model using FactoryBoy without touching models.py

I mean a simple model such as:

class SomeMod(models.Model):
    title = models.CharField(max_length=255, blank=True, null=True)
    description = models.CharField(max_length=255, blank=True, null=True)

    def __str__(self):
        return self.title

1 Answer 1

0

You may be looking for the attribute abstract in the Meta options of the factory class, which is mentioned here in Factory Boy documentation.

from factory.django import DjangoModelFactory
from factory import Faker

class MyAbstractFactory(DjangoModelFactory):
    title = Faker("last_name") # could be "company" or whatever you want to mock
    description = Faker("paragraph")

    class Meta:
         abstract = True

Is this what you're looking for? If not, please elaborate your question.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.