擅长:python、mysql、java
<p>尝试使用以下方法<code>Choices</code>:-</p>
<p>models.py</p>
<pre><code>choices = [
('choice1', 'choice1'),
('choice2',"choice2"),
('choice3',"choice3")
]
class Car(models.Model):
owner_name = models.CharField(max_length=100,unique=True)
car_type = models.CharField(max_length=24, choices=choices, default='choice1')
def __str__(self):
return self.owner_name
</code></pre>
<p>然后别忘了做<code>migrations</code></p>
<p>请参阅此-><a href="https://docs.djangoproject.com/en/3.0/ref/models/fields/#django.db.models.Field.choices" rel="nofollow noreferrer">https://docs.djangoproject.com/en/3.0/ref/models/fields/#django.db.models.Field.choices</a></p>