Default value for field in Django model
Posted
by Daniel Garcia
on Stack Overflow
See other posts from Stack Overflow
or by Daniel Garcia
Published on 2010-05-06T19:01:31Z
Indexed on
2010/05/06
19:08 UTC
Read the original article
Hit count: 508
Suppose I have a model:
class SomeModel(models.Model):
id = models.AutoField(primary_key=True)
a = models.IntegerField(max_length=10)
b = models.CharField(max_length=7)
Currently I am using the default admin to create/edit objects of this type. How do I set the field 'a' to have the same number as id? (default=???)
Other question
Suppose I have a model:
event_date = models.DateTimeField( null=True)
year = models.IntegerField( null=True)
month = models.CharField(max_length=50, null=True)
day = models.IntegerField( null=True)
How can i set the year, month and day fields by default to be the same as event_date field?
© Stack Overflow or respective owner