Reputation: 88459
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 ?
Upvotes: 10
Views: 15954
Reputation: 2257
you should use ForeignKey()
your_choice=models.ForeignKey(ChoiceList,on_delete=models.CASCADE)
Upvotes: 22