[Fixed]-Django model default

1👍

Try this:

def get_default():
    return OtherModel.get_first()

class MyModel(models.Model):
    field = models.ForeignKey(OtherModel, blank=False, null=False, default=get_default) 

You can also just hardcode pk but it’s ugly.

Leave a comment