Sunday, October 2, 2011

Re: Can model subclass change field options?

Hi Brian,

that works so far for displaying the correct choices in the admin
interface. But the problem now is the validation. He always tells me
that my choice is not a correct value.
I have been looking for a way to change validation but I can't figure
out how to do this...

Thanks for your help so far.

Jonas

Am 02.10.2011 19:41, schrieb Brian Mehrman:
> HI, Artemis,
>
> If I understand you correctly you want to use a Select Widget for your
> CharField. And feed your choices to the select widget.
>
> In your admin.py file of your app you will want to override the model's
> form field.
>
>
> # models.py
> from django.db import models
>
> myModel(models.Model):
> person = models.CharField()
> title = models.CharField()
>
> # admin.py
> from django.contrib import admin
> from django.forms import widgets
>
> myModelAdmin(admin.ModelAdmin):
> title = CharField(widget=widgets.Select(choices=('mr','mrs','miss'))
>
> admin.site.register(myModel, myModelAdmin)
>
> This code hasnt been tested but should be the route you want to take.
> You can find more info on widgets
> here(https://docs.djangoproject.com/en/1.3/ref/forms/widgets/). I hope
> this helps you.
>
> -Brian
>
> On Sun, Oct 2, 2011 at 12:20 PM, Artemis <cleve.jonas@googlemail.com
> <mailto:cleve.jonas@googlemail.com>> wrote:
>
> Hi,
>
> I have an model which contains a CharField.
> Now I want to have different subclasses of this model each one with
> different *choices* for the CharFiel. How can I implement this?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@googlegroups.com
> <mailto:django-users%2Bunsubscribe@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment