User to UserProfile access problem

2017-08-09 Thread Mike Dewhirst

Using Django 1.10 Admin with a legacy contrib.auth.user plus 1:1 userprofile

It works fine but I'm having trouble letting the user adjust their name 
and email address in contrib.auth.user.


Additionally, I reveal some of the user profile fields as an Admin 
inline under the Company model for users to edit their preferences.


I would like to include a view which incorporates selected fields from 
both models as a single inline under Company in the Admin. Is that 
possible? Should I instead retrofit a custom user?


Thanks

Mike

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b8f38ada-fa02-19bd-1987-6aad86d06773%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: combining user and userprofile in admin

2009-10-01 Thread Matt Schinckel



On Oct 2, 8:58 am, Matt Schinckel  wrote:
> On Oct 2, 3:20 am, booty  wrote:> I am creating an 
> application where I want the admin site to display
>
> > But I am not able to sort by these values (nor filter, nor search).
>


I seem to have missed this line.

You can use things in the search_fields attribute that look like
'user__username' to get access to related objects fields.

This doesn't seem to work for list_filter, though.

Matt.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: combining user and userprofile in admin

2009-10-01 Thread Matt Schinckel


On Oct 2, 3:20 am, booty <boot...@gmail.com> wrote:
> I am creating an application where I want the admin site to display
> the User and the UserProfile (my extensions to the User class)
> together in the list view.
>
[snip]

> My problem is that I want my User Profile fields to be displayed in
> the User list page (http://.../admin/auth/user/) and be able to filter
> and sort by these (User Profile) fields. But admin does not seem to
> get access to the get_profile method:
>
> list_display = ('first_name',
>                     'last_name',
>                      #get_profile, #adding this does not give access
>                    )
>
> I can of course write a function in MyUserAdmin to give access to
> individual UserProfile properties, and they will be diplayed
> correctly. e.g.
>
> class MyUserAdmin(UserAdmin):
>     inlines = [
>         UserProfileInline,
>     ]
>
>     def home_page(self):
>          return self.get_profile().home_page
>
>     list_display = ('first_name',
>                     'last_name',
>                     home_page
>                    )
>
> But I am not able to sort by these values (nor filter, nor search).
>
> Is there anyway to have the admin site have access to the UserProfile
> model as if it was part of the User model?

Methods and properties that you have in either the AdminModel, or the
Model itself, that take no arguments, can be used in the
list_display.  Which appears to be what you have done.

Is there anything else you are trying to achieve other than this?

Matt.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



combining user and userprofile in admin

2009-10-01 Thread booty

I am creating an application where I want the admin site to display
the User and the UserProfile (my extensions to the User class)
together in the list view.

Currently, I have something like:

class UserProfile(models.Model):
" User profile class "
# That field link toward the django user class
user=models.ForeignKey(User, unique=True)

personal_title=models.CharField(max_length=20, null=True,
blank=True)
phone=models.CharField('telephone number',
   max_length=50,
   null=True, blank=True,
   help_text='Please include the country
code')


I am displaying the my own version of User in the admin site like
this:

class UserProfileInline(admin.StackedInline):
model = UserProfile

class MyUserAdmin(UserAdmin):
inlines = [
UserProfileInline,
]

admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)


My problem is that I want my User Profile fields to be displayed in
the User list page (http://.../admin/auth/user/) and be able to filter
and sort by these (User Profile) fields. But admin does not seem to
get access to the get_profile method:

list_display = ('first_name',
'last_name',
 #get_profile, #adding this does not give access
   )

I can of course write a function in MyUserAdmin to give access to
individual UserProfile properties, and they will be diplayed
correctly. e.g.

class MyUserAdmin(UserAdmin):
inlines = [
UserProfileInline,
]

def home_page(self):
 return self.get_profile().home_page

list_display = ('first_name',
'last_name',
home_page
   )

But I am not able to sort by these values (nor filter, nor search).

Is there anyway to have the admin site have access to the UserProfile
model as if it was part of the User model?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Design question: User vs. UserProfile

2009-09-18 Thread Léon Dignòn

The user model, because the model defined by AUTH_PROFILE_MODULE is
intended to be an extension to the actual user model. Namely the
profile.

Why would you bind something to a user's profile, instead of the user
itsself? If you want to "allow records of people without Users", then
use blank=True and null=True at the foreign key (here: model Song).

-ld

On Sep 18, 6:21 pm, Tiago Serafim  wrote:
> I`d go with the first. It`s easier to get the current logged in user and all
> other pluggable apps use User, so it's a common thing to do and you can
> integrate things easily .
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Design question: User vs. UserProfile

2009-09-18 Thread Tiago Serafim
I`d go with the first. It`s easier to get the current logged in user and all
other pluggable apps use User, so it's a common thing to do and you can
integrate things easily .

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Design question: User vs. UserProfile

2009-09-18 Thread Grant Livingston
I'm still making my first site with django so I don't how much weight my
opinion has, but I used a seperate profile for ForeignKeys. I don't know
why, it just seemed logical at the time. It is easer as you can refer to
whats in a users profile easier. You can put things like {{
song.profile.user.username }} or {{ song.profile.song_set }} .

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: User and UserProfile

2007-05-04 Thread Mi Reflejo
Nevermind.

Thank you Russ and BTW if someone is thinking "How can i make a generic
callback function for that purpose?"
http://www.djangosnippets.org/snippets/209/


Regards,
-- 
Martín Conte Mac Donell
http://www.catartico.com

On 5/3/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
>
>
> On 5/4/07, Mi Reflejo <[EMAIL PROTECTED]> wrote:
> > I just figured i can use a callback function in form_for_model.
> Something
> > like:
> >
> > def uform_callback(f, **kwargs):
> > "tell forms to ignore other fields differents for visible_field"
> > visible_fields = ['username', 'password', 'first_name', 'last_name']
> > if f.name not in visible_fields:
> > return None
> > return f.formfield(**kwargs)
> >
> > Is there another elegant way? :)
>
> Right now - no. However, I'm trying to get a discussion going on the
> dev list about this issue.
>
> Yours,
> Russ Magee %-)
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: User and UserProfile

2007-05-03 Thread Russell Keith-Magee

On 5/4/07, Mi Reflejo <[EMAIL PROTECTED]> wrote:
> I just figured i can use a callback function in form_for_model. Something
> like:
>
> def uform_callback(f, **kwargs):
> "tell forms to ignore other fields differents for visible_field"
> visible_fields = ['username', 'password', 'first_name', 'last_name']
> if f.name not in visible_fields:
> return None
> return f.formfield(**kwargs)
>
> Is there another elegant way? :)

Right now - no. However, I'm trying to get a discussion going on the
dev list about this issue.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: User and UserProfile

2007-05-03 Thread Daniel Arbanas

Mi Reflejo wrote:
> Thank you, it helps me.
> 
> Now lets supose that i don't want to show some fields from Users model. For
> example: last_login
> 
> The only way that I've found is
> del UserFormModel.base_fields['last_login']
> 
> But in the other hand, i need to fill this value with datetime.datetime.now
> ().
> 
> So i can't just delete dictionary entry. i could add "editable=false" If it
> was my model, but how can i do it for User model?
> 
> Thank you again,

Hi,

to hide some field use HiddenInput widget

UserFormModel.base_fields['last_login'].widget = widgets.HiddenInput()

hope it helps

BR,
-- 
Daniel Arbanas

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: User and UserProfile

2007-05-03 Thread Mi Reflejo
I just figured i can use a callback function in form_for_model. Something
like:

def uform_callback(f, **kwargs):
"tell forms to ignore other fields differents for visible_field"
visible_fields = ['username', 'password', 'first_name', 'last_name']
if f.name not in visible_fields:
return None
return f.formfield(**kwargs)

Is there another elegant way? :)

Thank you!
-- 
Martín Conte Mac Donell
http://www.catartico.com

On 5/3/07, Mi Reflejo <[EMAIL PROTECTED]> wrote:
>
> Thank you, it helps me.
>
> Now lets supose that i don't want to show some fields from Users model.
> For example: last_login
>
> The only way that I've found is
> del UserFormModel.base_fields['last_login']
>
> But in the other hand, i need to fill this value with
> datetime.datetime.now().
>
> So i can't just delete dictionary entry. i could add "editable=false" If
> it was my model, but how can i do it for User model?
>
> Thank you again,
> --
> Martín Conte Mac Donell
> http://www.catartico.com
>
> On 5/3/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
> >
> >
> > On 5/3/07, Mi Reflejo <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > >
> > > I don't know how to do it using form_for_model (I want to keep my
> > "labels",
> > > "help_text", etc from models). Of course i could make my own Form
> > class with
> > > each field but it's redundant and if i change my database struct i
> > should
> > > change the code.
> >
> > The easiest solution is to simply use 2 forms. Use form_for_model to
> > define one form for User, and one for the profile. Pass them both into
> > the template, check them both for validity, and save both if they are
> > ok.
> >
> > > PD. Is there another way to create users than User.objects.create_user
> > ()?
> > > (create_user is setting first_name and last_name to '')
> >
> > Well... yes, there is.
> >
> > newuser = User()
> > newuser.save()
> >
> > create_user() is just a manager-level wrapper around basic model
> > saving logic. Feel free to define your own implementation if you want
> > different behaviour.
> >
> > Yours,
> > Russ Magee %-)
> >
> > > >
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: User and UserProfile

2007-05-03 Thread Mi Reflejo
Thank you, it helps me.

Now lets supose that i don't want to show some fields from Users model. For
example: last_login

The only way that I've found is
del UserFormModel.base_fields['last_login']

But in the other hand, i need to fill this value with datetime.datetime.now
().

So i can't just delete dictionary entry. i could add "editable=false" If it
was my model, but how can i do it for User model?

Thank you again,
-- 
Martín Conte Mac Donell
http://www.catartico.com

On 5/3/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
>
>
> On 5/3/07, Mi Reflejo <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I don't know how to do it using form_for_model (I want to keep my
> "labels",
> > "help_text", etc from models). Of course i could make my own Form class
> with
> > each field but it's redundant and if i change my database struct i
> should
> > change the code.
>
> The easiest solution is to simply use 2 forms. Use form_for_model to
> define one form for User, and one for the profile. Pass them both into
> the template, check them both for validity, and save both if they are
> ok.
>
> > PD. Is there another way to create users than User.objects.create_user
> ()?
> > (create_user is setting first_name and last_name to '')
>
> Well... yes, there is.
>
> newuser = User()
> newuser.save()
>
> create_user() is just a manager-level wrapper around basic model
> saving logic. Feel free to define your own implementation if you want
> different behaviour.
>
> Yours,
> Russ Magee %-)
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: User and UserProfile

2007-05-03 Thread Russell Keith-Magee

On 5/3/07, Mi Reflejo <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I don't know how to do it using form_for_model (I want to keep my "labels",
> "help_text", etc from models). Of course i could make my own Form class with
> each field but it's redundant and if i change my database struct i should
> change the code.

The easiest solution is to simply use 2 forms. Use form_for_model to
define one form for User, and one for the profile. Pass them both into
the template, check them both for validity, and save both if they are
ok.

> PD. Is there another way to create users than User.objects.create_user()?
> (create_user is setting first_name and last_name to '')

Well... yes, there is.

newuser = User()
newuser.save()

create_user() is just a manager-level wrapper around basic model
saving logic. Feel free to define your own implementation if you want
different behaviour.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



User and UserProfile

2007-05-03 Thread Mi Reflejo
Hi,

I'm facing a problem and i don't know how to solve it.
I'm using the User class "expanded" by ForeingKey [UserProfile] and I need
to make a frontend (newforms) for signup. The form should show User fields
(first_name, last_name, user, pass) and UserProfile fields.

 So there is the problem:

I don't know how to do it using form_for_model (I want to keep my "labels",
"help_text", etc from models). Of course i could make my own Form class with
each field but it's redundant and if i change my database struct i should
change the code.

It'll be great if there is a easy way like "add edit_inline in your model"
:)

PD. Is there another way to create users than User.objects.create_user()?
(create_user is setting first_name and last_name to '')


Regards,
-- 
Martín Conte Mac Donell
http://www.catartico.com

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---