Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Custom ModelAdmin form for distinct logged users [RSS Feed]

#1 Jan. 28, 2011 00:22:11

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Custom ModelAdmin form for distinct logged users


Hello,

How can I customize a form by the user who is logged in?
For example, if the user is_superuser(), i need to display the
standard admin form, but if the user is another one, show only some
fields and not all model fields. For this, I coud use
ModelAdmin.fields (or exclude, or readonly_fields), but i don't know
how to make it conditional to the user.

Regards, Mario.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 28, 2011 06:34:40

h.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Custom ModelAdmin form for distinct logged users


You can use proxy models. Refer tohttp://stackoverflow.com/questions/2223375/multiplue-modeladmins-views-for-same-model-in-django-adminOn 1月27日, 下午4时22分, Mario8k <mm...@8ksoft.com.ar> wrote:
> Hello,
>
> How can I customize a form by the user who is logged in?
> For example, if the user is_superuser(), i need to display the
> standard admin form, but if the user is another one, show only some
> fields and not all model fields. For this, I coud use
> ModelAdmin.fields (or exclude, or readonly_fields), but i don't know
> how to make it conditional to the user.
>
> Regards, Mario.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 28, 2011 22:11:50

Moya, M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Custom ModelAdmin form for distinct logged users


2011/1/28 hollando <hrqi...@gmail.com>

Hi hollando,

You can use proxy models. Refer to
>
>http://stackoverflow.com/questions/2223375/multiplue-modeladmins-views-for-same-model-in-django-admin>

I can't set permissions for proxy models, i think because the table
auth_permissions doesn't have the proxy records.
That is, i have the Foo model and the FooProxy. Whe i loggin as superuser i
see both, Foo and FooProxy admin forms. But when i log as other user (supose
proxyuser), who only have the permission "Can change foo", only see Foo
admin forms.

How can i reach the way to login as proxyuser, and enter only to the
FooProxy admin forms?


>
> On 1月27日, 下午4时22分, Mario8k <mm...@8ksoft.com.ar> wrote:
> > Hello,
> >
> > How can I customize a form by the user who is logged in?
> > For example, if the user is_superuser(), i need to display the
> > standard admin form, but if the user is another one, show only some
> > fields and not all model fields. For this, I coud use
> > ModelAdmin.fields (or exclude, or readonly_fields), but i don't know
> > how to make it conditional to the user.
> >
> > Regards, Mario.
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>


--
Lic. Mario Moya
Tel: +54 299 4771196
Cel: +54 299 155023987
mm...@8ksoft.com.ar
Belgrano 167 - (8324) Cipolletti, Río Negrohttp://www.8ksoft.com.ar*Cuidar el medio ambiente depende de todos, imprime sólo lo necesario.*

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Jan. 28, 2011 22:54:12

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Custom ModelAdmin form for distinct logged users


On Friday, January 28, 2011 12:22:04 AM UTC, Mario8k wrote:
>
> Hello,
>
> How can I customize a form by the user who is logged in?
> For example, if the user is_superuser(), i need to display the
> standard admin form, but if the user is another one, show only some
> fields and not all model fields. For this, I coud use
> ModelAdmin.fields (or exclude, or readonly_fields), but i don't know
> how to make it conditional to the user.
>
> Regards, Mario.
>

Since this is in the admin, there's a hook especially for this
- ModelAdmin.get_form(). This is a method that you can override in your own
ModelAdmin subclass - it's passed the request so you can check the value of
request.user and return the appropriate form. See the code in
django.contrib.admin.options.
--
DR.

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Custom ModelAdmin form for distinct logged users [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support