On 7/26/10 4:08 AM, Daniel Roseman wrote:
On Jul 26, 8:49 am, gondor<[email protected]> wrote:
I am using admin panel and using get_form to retrieve one of my table
objects. I have a choicefield in this object but I don't know how to
set the default. I have saw numerous examples of using the
following:
class MyAdmin(admin.ModelAdmin):
list_display = ('rank', 'name')
def get_form(self,request,obj=None,**kwargs):
return super(MyAdmin,self).get_form(request, obj=None, **kwargs)
rank is a choicefield.
choices are 1,2,3,4
right now it defaults to '-------' and I want it to default to 1.
I'm wanting to do this because without it i'm getting a "Incorrect
integer value: '' for column 'rank' at row 1 error
the '------' is giving me a empty value and I need something there or
a method to handle this error ?
Thanx
The problem is that somewhere you have specified this field as
required=False (or, in the model, blank=True). Without that, Django
doesn't add the blank option, and it will default to the first value
in the list (1).
--
DR.
Thanx DR.
Looking at your suggestion I started playing with the model and it turns
out there is a default that I can set in the model that sets the default
for models widgets. Removing the default didn't work but it did turn
off the error message by checking for a input so I didn't have to see
the annoying error message anymore.
In this case I didn't find anything on google on this specific use but
it was a simple change to the model by adding the following:
model.py:
rank = models.CharField(max_length=1, choices=RANK, default='1')
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.