默认情况下Django Admin字段的值



我有以下型号的

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中有一个默认值,我该怎么办?

关于

将URL存储为CharField而不是URLField有什么原因吗?URLField是CharField的一个特定于URL的子类。此外,要设置默认值,请使用default="x",例如

url = models.URLField(default='http://www.foo.com')

希望能有所帮助。

最新更新