After some digging around, it looks like the newforms-admin branch
does not allow widget declarations within the model class itself.
However, adding a custom widget is quite easy.

In the branch, almost all of the admin app functionality has been
moved out of the inner Admin class and into a separate class called
ModelAdmin. If you want to customize the admin app's behavior, simply
subclass ModelAdmin and override the default functionality.

For example, look at this sample ModelAdmin subclass:

-----

from django.contrib import admin

[...]

class ProfileOptions(admin.ModelAdmin):
        list_display = ('display_name', 'headline','setup_date')
        filter_horizontal = ('techniques', 'products', 'setup')
        fields = (('Administrative Settings',{'fields':
('subscriber','active')}),('Contact Information',{'fields':
('phone_numbers','im_accounts','zip_code')}),('Photos',{'fields':
('primary_photo','secondary_photos','private_photos')}),)

        def formfield_for_dbfield(self, db_field, **kwargs):
                if db_field.name == 'zip_code':
                        return ZipCodeField(**kwargs)
                else:
                        return 
super(ProfileOptions,self).formfield_for_dbfield(db_field,
**kwargs)

        def queryset(self, request):
                return self.model.user_profiles.get_query_set()


adminsite.register(Profile,ProfileOptions)

----


list_display and fields are used exactly as they were in inner Admin
classes. filter_horizontal is simply a tuple of fields that will use
the javascript multiple-select filter.

The queryset() function allows you to specify which manager should be
used to obtain the change list objects.

Then there's formfield_for_dbfield(), a function that allows you to
override the default form field types that are returned for your
models' fields. In this example, the function returns a custom field
class (ZipCodeField) for any model field named "zip_code".

Alternatively, you could specify a custom widget like so:

                if db_field.name == 'zip_code':
                        kwargs['widget'] = WIDGET
                return 
super(ProfileOptions,self).formfield_for_dbfield(db_field,
**kwargs)

Finally, don't forget to register your ModelAdmin subclass for the
model.

You can find more information on the branch's homepage:

http://code.djangoproject.com/wiki/NewformsAdminBranch

I hope this helps! If I am wrong about any of this, please post so
others don't repeat my mistakes.

Cheers,
LS



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to