Django model choice field from another model instance

Viewed 11709

In my models.py, I have two classes, ChoiceList and SampleModel as below

class ChoiceList(models.Model):
    choice=models.CharField(max_length=15)

class SampleModel(models.Model):
    CHOICELIST=ChoiceList.objects.all()
    name=models.CharField(max_length=15)
    your_choice=models.CharField(max_length=15,choices=ChoiceList)

I need to add your_choice field data only from ChoiceList instances. Can I add data in that way ?

When I doing this way, I got error as django.db.utils.OperationalError: no such table: rest_api_ChoiceList
Can anyone solve the problem ?

1 Answers
Related