On Wed, Mar 11, 2009 at 10:33 AM, Alex Jillard <mez...@gmail.com> wrote:

> I'm trying to populate an admin form with the field names of of a model
> class, but I don't want to have to instantiate that model just to read it's
> fields from _meta.
>
> I basically want to do something like this:
>
> self.fields['sort_by'].choices = [(field.verbose_name, field.name) for
> field in field_list]
>
> field_list would be the equivalent to model_instance._meta.fields, but
> without requiring the model instance.
>
> I know I could just grab an instance of the model from the database, but
> I'd like this to work even if there are no instances currently saved.
>
> >
>
_meta exists on the class as well, so on a ModelAdmin you can do
self.model._meta.fields

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to