Free-form input for ForeignKey Field on a Django ModelForm

后端 未结 4 479
夕颜
夕颜 2021-02-03 09:52

I have two models related by a foreign key:

# models.py    
class TestSource(models.Model):
  name        = models.CharField(max_length=100)

class TestModel(mod         


        
4条回答
  •  醉酒成梦
    2021-02-03 10:37

    TestForm.attribution expects int value - key to TestSource model.

    Maybe this version of the model will be more convenient for you:

    class TestSource(models.Model):
        name = models.CharField(max_length=100, primary_key=True)
    

提交回复
热议问题