人々が私と同じことをするのを数回(1回、2回)見つけました:
class TempUser(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
bank_account = models.ForeignKey(BankAccount)
def save(self, *args, **kwargs):
if not self.bank_account:
bank_account = BankAccount()
bank_account.save()
self.bank_account = bank_account
super(TempUser, self).save(*args, **kwargs)
しかし、私は次の例外を得ました:
File "models.py", line 134, in main
fill_predefined_data()
File "models.py", line 121, in fill_predefined_data
user.save()
File "models.py", line 41, in save
if not self.bank_account:
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 343, in __get__
raise self.field.rel.to.DoesNotExist
__main__.DoesNotExist