How do you specify a default for the Django ForeignKey field?
AFAIK Django won't execute a QuerySet passed as a param, even if it's limited to one element. You should try something like proposed in this post
class Foo(models.Model):
a = models.CharField(max_length=10)
def get_foo():
return Foo.objects.get_or_create(id=1)
class Bar(models.Model):
b = models.CharField(max_length=10)
a = models.ForeignKey(Foo, default=get_foo)
Because get_or_create
returns a tuple, I think this is a better solution
def get_default():
result, _ = Foo.objects.get_or_create(id=1)
return result
than this
return Foo.objects.get_or_create(id=1)