私は2つのモデルを持っています:
class Profile(models.Model):
    # (...)
    settings = models.OneToOneField('Settings', null=True)
    # (...)
class Settings(model.Model):
    # (...)
Profile#settingsにアクセスするたびにSettingsのインスタンスを作成する方法はありますか?
更新:これが必要な主な動機は、プロファイルモデルがすでにあり、ユーザーがProfile#settingインスタンスを必要とするアプリのポイントに到達したときに、作成されているかどうかを気にせずに、設定リレーションを遅延して作成することです。か否か。
更新: @ miki725は、これはすでにDjangoによって処理されていると以下に述べています。私は次のことを試しました:
class SettingsTest(TestCase):
    def setUp(self):
        user = User.objects.create(username='felipe', email='something@aol.com')
        self.profile = Profile.objects.create(short_name='Felipe', name='Felipe',
            user=user)
    def test_settings(self):
        self.assertIsNotNone(self.profile.settings)
そして私はこれを手に入れます:
Creating test database for alias 'default'...
F
======================================================================
FAIL: test_settings (activity.tests.settings.SettingsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/vagrant/activity/tests/settings.py", line 20, in test_settings
    self.assertIsNotNone(self.profile.settings)
AssertionError: unexpectedly None
----------------------------------------------------------------------
Ran 1 test in 0.003s