我有以下型号
class Trivias(models.Model):
GIFT_CHOICES = (
('gas', 'Gasolina'),
('money', 'Dinero'),
('xp','Experiencia'),
)
NUMQ_CHOICES = (
(1, '1'),
(2, '2'),
(3, '3'),
(4, '4'),
)
idtrivias = models.IntegerField(primary_key=True)
url = models.CharField(max_length=450)
numQ = models.IntegerField(max_length=4,choices=NUMQ_CHOICES)
idtipospropiedades = models.ForeignKey(Tipospropiedades, db_column='idtipospropiedades')
idtitulos = models.ForeignKey(Titulos, db_column='idtitulos')
correct = models.IntegerField(max_length=1)
gift = models.CharField(max_length=5,choices=GIFT_CHOICES)
value = models.CharField(max_length=20)
class Meta:
db_table = u'trivias'
我希望url字段在Django Admin中有一个默认值,我该怎么做?
问候
答案 0 :(得分:2)
是否有任何理由将您的网址存储为CharField而不是URLField? URLField是CharField的特定于URL的子类。另外,要设置默认值,请使用default="x",例如
url = models.URLField(default='http://www.foo.com')
希望有所帮助。