Tech Forum Network

Programming, technical solutions and hot scripts
Home » TechQns » Default value for field in Django model

Default value for field in Django model

April 16, 2009 Posted by forumadmin under TechQns
Comments off

Suppose I have a model:

class SomeModel(models.Model):
    id = models.AutoField(primary_key=True)
    a = models.CharField(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 remove the field b from the admin so that each object cannot be created with a value, and rather will receive a default value of 0000000?

 

Asked By – Yuval Adam        Read Answers    

More Related Questions

  • Adding model-wide help text to a django models admin form In my django app, I would like to be able to add customized help text to the admin change form for some of my models. Note I'm not talking about the field specific help_text attribute […]
  • Django reverse foreign key in admin I have a Django related question about foreign keys in the admin panel. I'm facing the following situation: class Driver(models.Model): name = models.CharField(max_length=200) […]
  • Django auto_now and auto_now_add For Django 1.1. I have this in my models.py: class User(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) When […]
  • Dynamic rendering of template I have a model class Product in which I am storing generic things related to a product like name, owner, price, image and type. Here the type attribute represents the category of the […]
  • Resize fields in Django Admin Django tends to fill up horizontal space when adding or editing entries on the admin, but, in some cases, is a real waste of space, when, i.e., editing a date field, 8 characters wide, or […]
  • Admin interface for Gallery App I want to create me admin like this: http://lightbird.net/dbe/_static/p1.png What I have right now is: def get_upload_file_name(instance, filename): new_file_path_and_name = […]
  • Performing a ModelAdmin action in Django I'd like to be able to do something like: # from the docs def make_published(modeladmin, request, queryset): queryset.update(status='p') But I'm not using the Django admin site - I […]
  • Unique BooleanField value in Django? Suppose my models.py is like so: class Character(models.Model): name = models.CharField(max_length=255) is_the_chosen_one = models.BooleanField() I want only one of my Character […]
  • Django TabularInline using popup to add/edit item intead of the inline inputs In Django admin when using TabularInline for inline models, is there an option to add/edit an item by using a popup? I'm especially wondering about when we have multiple fields.  […]
  • How to store IP address in the database and django admin Would like to store IP address of everybody who is coming to the site. What is the best approach to do this. Lets say have model class ip(models.Model): pub_date = […]
0
  
Email
Tags: django, django-admin, django-models, python

Comments are closed.

« HTML form with single text field + preventing postback in Internet Explorer
Strategy for coping with database identity/autonumber maxing out »
Tech Forum Network powered by WordPress and The Clear Line Theme