{"id":4505,"library":"django-fake-model","title":"Django Fake Model","description":"django-fake-model is a simple Python library designed for creating temporary, in-memory Django models specifically for unit testing purposes. It allows developers to quickly define and use fake models within their tests without polluting the main database schema, facilitating isolated and efficient testing. The current version is 0.1.4, and its release cadence has been very slow, with the last update in 2017.","status":"maintenance","version":"0.1.4","language":"en","source_language":"en","source_url":"https://github.com/erm0l0v/django-fake-model","tags":["django","testing","mocking","models"],"install":[{"cmd":"pip install django-fake-model","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for functionality; designed to be used exclusively within Django projects.","package":"Django","optional":false}],"imports":[{"symbol":"model_me","correct":"from fake_model import model_me"},{"symbol":"fake_me","correct":"from fake_model import fake_me"}],"quickstart":{"code":"import unittest\nfrom django.test import TestCase\nfrom django.db import models\nfrom fake_model import model_me\n\nclass MyFakeModelTest(TestCase):\n    \"\"\"\n    Example demonstrating the model_me decorator for creating a temporary Django model.\n    To execute this test, ensure you have a Django project configured and run it\n    via `python manage.py test your_app_name`.\n    \"\"\"\n    @model_me('my_app', 'MyFakeModel', fields={\n        'name': models.CharField(max_length=255),\n        'value': models.IntegerField(default=0),\n    })\n    def test_create_and_query_fake_model(self, MyFakeModel):\n        # MyFakeModel is a temporary model class, available only within this test method\n        self.assertFalse(MyFakeModel.objects.exists()) # Should be empty initially\n\n        instance = MyFakeModel.objects.create(name='Test Item', value=42)\n        self.assertEqual(instance.name, 'Test Item')\n        self.assertEqual(instance.value, 42)\n\n        retrieved = MyFakeModel.objects.get(name='Test Item')\n        self.assertEqual(retrieved.pk, instance.pk)\n        self.assertEqual(retrieved.value, 42)\n\n        self.assertEqual(MyFakeModel.objects.count(), 1)\n","lang":"python","description":"This quickstart demonstrates how to use the `model_me` decorator to create a temporary Django model for a specific test method. The fake model is automatically registered and unregistered, ensuring test isolation. This code snippet should be placed within a Django test file and run as part of a Django test suite."},"warnings":[{"fix":"For newer Django projects, consider using more actively maintained alternatives like `django-dynamic-models` or manual test-model creation. If absolutely necessary, pin Django to 1.9 and Python to 3.7 or earlier.","message":"The library has not been updated since 2017 and is likely incompatible with modern Django versions (3.x, 4.x, 5.x) and newer Python versions (3.8+). It was last officially tested with Django 1.9.","severity":"breaking","affected_versions":"All versions (0.1.x) when used with Django > 1.9 or Python > 3.7"},{"fix":"Carefully evaluate the long-term implications of using an unmaintained library. For new development, prioritize actively supported tools.","message":"The lack of active maintenance since 2017 means the library may have unpatched bugs, security vulnerabilities, or simply not function as expected with contemporary Django ecosystem components.","severity":"gotcha","affected_versions":"All versions (0.1.x)"},{"fix":"Ensure you are using version 0.1.3 or higher to reliably use multiple fake models within your tests.","message":"Prior to version 0.1.3, defining and using multiple fake models within the same test context could lead to unexpected behavior or conflicts. This was fixed in 0.1.3.","severity":"gotcha","affected_versions":"<0.1.3"},{"fix":"Upgrade to version 0.1.4 for `nose` compatibility. For other test runners (e.g., `pytest-django`), verify functionality explicitly or consider using `model_me` which might be more robust across different setups.","message":"Version 0.1.4 specifically fixed issues related to the `fake_me` class decorator when used with `nose` tests. If you are using `fake_me` with other test runners, thoroughly test its behavior.","severity":"gotcha","affected_versions":"<0.1.4, potentially 0.1.4 with non-nose runners"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}