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.

-- 
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.

Reply via email to