Re: Customizing Admin Forms Question
2010/1/16 Joel Davis <joeld42@gmail.com>:
> I've got a couple of questions about customizing the admin pages...
>
> First, is there a way to specify the layout/template for an admin form
> by hand? I've got a Model that has a bunch of optional fields,
> including a bunch of TextAreas, and the form is huge and jumbled. I'd
> like to make a custom template for it, use JS to hide the optional
> bits by default, and layout the fields in something other than a big
> stack.
Here's how to specify another template for a certain model -
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#set-up-your-projects-admin-template-directories
An alternative way of doing what you want is to use fieldsets, and
specify CSS classes to hide. There's an example here -
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-options
> Second, is there a way to add fields to an Admin form that don't get
> added to the model? For example, I've got an imagefield, and when it
> calls save(), it autogenerates a thumbnail, that works fine, but I
> might like to have some extra controls to customize the behavior of
> the thumbnail generation, but these don't need to get stored in the DB
> anywhere..
Start with creating a ModelForm for that model
(http://docs.djangoproject.com/en/dev/topics/forms/modelforms/). This
will automatically add the model's fields into the form. You can then
add the additional fields there, and also override methods to deal
with them.
Then use ModelAdmin to tell Django to use that form for that model -
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-objects
If there's not enough control there, you can even override the view
methods in the ModelAdmin; you pretty much have complete control now.
> Thanks!
> Joel
>
> --
> 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.
>
>
>
>
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home