195👍
✅
Set editable
to False
and default
to your default value.
http://docs.djangoproject.com/en/stable/ref/models/fields/#editable
b = models.CharField(max_length=7, default='0000000', editable=False)
Also, your id
field is unnecessary. Django will add it automatically.
27👍
You can also use a callable in the default field, such as:
b = models.CharField(max_length=7, default=foo)
And then define the callable:
def foo():
return 'bar'
- [Django]-Nginx doesn't serve static
- [Django]-Django count RawQuerySet
- [Django]-Django – How to pass several arguments to the url template tag
26👍
You can set the default like this:
b = models.CharField(max_length=7,default="foobar")
and then you can hide the field with your model’s Admin class like this:
class SomeModelAdmin(admin.ModelAdmin):
exclude = ("b")
- [Django]-How can I enable CORS on Django REST Framework
- [Django]-Django testing: Test the initial value of a form field
- [Django]-Login Page by using django forms
Source:stackexchange.com