Re: multiple profile

2012-08-14 Thread Tomas Neme
Well, it depends on what you want to do exactly, you could create something
like this:

class UserProfile(models.Model):
common_data

class ClientProfile(UserProfile):
specific_data

class StudentProfile(UserProfile):
specific_data

class TeacherProfile(UserProfile):
specific_data

...

AUTH_PROFILE_MODULE = 'appname.UserProfile'

This would ensure that 3rd party apps that don't know about your
3-user-types system work in your site, but whether you do this, or ignore
AUTH_PROFILE_MODULE, you'll have to set up a specific way of creating the
profiles on user creation. Save signals are your friend here, probably,
and/or the views you use to create the different types of user.

-- 
"The whole of Japan is pure invention. There is no such country, there are
no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
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: multiple profile

2012-08-13 Thread Melvyn Sopacua
On 13-8-2012 21:51, Anderson wrote:

> I have 3 types of users
> 
> Clients
> Students
> Teachers
> 
> and each one have different fields and AUTH_PROFILE_MODULE is not going to
> work with 3 profiles.

Yeah, the auth module doesn't support this very well. I'd recommend
storing the shared information and a type field in the
AUTH_PROFILE_MODULE model.
So:
AUTH_PROFILE_MODULE = app.Shared
class Shared(models.Model)
type = 'client_profile'
birth_date = ...
# more shared fields

class ClientProfile(models.Model)
shared = models.OneToOneField(Shared, related_name='client_profile')

then you can do:
shared_profile = User.get_profile()
client_profile = shared_profile.client_profile

Or even dynamically, if you make sure shared.type matches extended's
related_name:
shared_profile = User.get_profile()
extended_profile = getattr(shared_profile, shared_profile.type)

-- 
Melvyn Sopacua

-- 
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: multiple profile

2012-08-13 Thread Anderson
Sorry :D


I have 3 types of users

Clients
Students
Teachers

and each one have different fields and AUTH_PROFILE_MODULE is not going to
work with 3 profiles.



-- 
Anderson Dias Borges
Senior Analyst Developer

Tu cumprirás o desejo do meu coração se eu Te buscar...
I can't see but I'll take my chances
To hear You call my name

-- 
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: multiple profile

2012-08-13 Thread Marcin Tustin
You're going to have to be more specific.

On Mon, Aug 13, 2012 at 3:36 PM, Anderson <andersondbor...@gmail.com> wrote:

> What's the best way to work with multiple profile on Django?
>
> --
> Anderson Dias Borges
> Senior Analyst Developer
>
> Tu cumprirás o desejo do meu coração se eu Te buscar...
> I can't see but I'll take my chances
> To hear You call my name
>
> --
> 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.
>



-- 
Marcin Tustin
Tel: 07773 787 105

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



multiple profile

2012-08-13 Thread Anderson
What's the best way to work with multiple profile on Django?

-- 
Anderson Dias Borges
Senior Analyst Developer

Tu cumprirás o desejo do meu coração se eu Te buscar...
I can't see but I'll take my chances
To hear You call my name

-- 
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: help needed with multiple profile images with UserProfile

2012-02-24 Thread richard
Thanks tom,

that worked and now understand what i was doing wrong.

much appreciated.

On Feb 24, 7:08 am, Tom Evans  wrote:
> On Fri, Feb 24, 2012 at 2:55 PM, richard  wrote:
> > Hi Tom,
>
> > Thanks for your reply. So for clarity i thought i was getting the
> > userprofile to pass into the bound form so that the userprofile_id in
> > the UserProfilePic would get populated/saved. as if i leave the
> > instance as None
> > then i get an error saying that userprofile_id cannot be empty?
>
> Correct. So when you are creating a new UserProfilePic object, you
> will need to populate those fields manually. I know of a couple of
> techniques:
>
> 1) Do it manually:
>
> frm = UserProfilePicForm(request.POST, instance=None)
> if frm.is_valid():
>   instance = frm.save(commit=False)
>   instance.userprofile = user.get_profile()
>   instance.save()
>
> 2) Pass the profile to the form's constructor, override the save
> method and implement the same logic there:
> class UserProfilePicForm(ModelForm):
>   def __init__(self, *args, **kwargs):
>     self.profile = kwargs.pop('profile')
>   def save(self, commit=True, *args, **kwargs):
>     instance = super(UserProfilePicForm, self).save(commit=False,
> *args, **kwargs)
>     instance.userprofile = self.profile
>     if commit:
>       instance.save()
>     return instance
>   class Meta:
>     model = UserProfilePic
>     fields = ('profilepic',)
>
> >also,
> > is a 1 to may relationship here correct for what i want to achieve?
>
> Probably. You don't want multiple profiles linking to the same picture
> do you? IE each picture has exactly one owner.
>
> Cheers
>
> Tom

-- 
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: help needed with multiple profile images with UserProfile

2012-02-24 Thread Tom Evans
On Fri, Feb 24, 2012 at 2:55 PM, richard  wrote:
> Hi Tom,
>
> Thanks for your reply. So for clarity i thought i was getting the
> userprofile to pass into the bound form so that the userprofile_id in
> the UserProfilePic would get populated/saved. as if i leave the
> instance as None
> then i get an error saying that userprofile_id cannot be empty?

Correct. So when you are creating a new UserProfilePic object, you
will need to populate those fields manually. I know of a couple of
techniques:

1) Do it manually:

frm = UserProfilePicForm(request.POST, instance=None)
if frm.is_valid():
  instance = frm.save(commit=False)
  instance.userprofile = user.get_profile()
  instance.save()

2) Pass the profile to the form's constructor, override the save
method and implement the same logic there:
class UserProfilePicForm(ModelForm):
  def __init__(self, *args, **kwargs):
self.profile = kwargs.pop('profile')
  def save(self, commit=True, *args, **kwargs):
instance = super(UserProfilePicForm, self).save(commit=False,
*args, **kwargs)
instance.userprofile = self.profile
if commit:
  instance.save()
return instance
  class Meta:
model = UserProfilePic
fields = ('profilepic',)


>also,
> is a 1 to may relationship here correct for what i want to achieve?
>

Probably. You don't want multiple profiles linking to the same picture
do you? IE each picture has exactly one owner.

Cheers

Tom

-- 
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: help needed with multiple profile images with UserProfile

2012-02-24 Thread richard
Hi Tom,

Thanks for your reply. So for clarity i thought i was getting the
userprofile to pass into the bound form so that the userprofile_id in
the UserProfilePic would get populated/saved. as if i leave the
instance as None
then i get an error saying that userprofile_id cannot be empty? also,
is a 1 to may relationship here correct for what i want to achieve?


On Feb 24, 6:47 am, Tom Evans  wrote:
> On Fri, Feb 24, 2012 at 2:20 PM, richard  wrote:
> > Hi, Am i doing this in the correct way?
> > […]
>
> > any help would be greatly appreciated.
>
> > […]
>
> > from .models import UserProfilePic
> > class UserProfilePicForm(ModelForm):
> >    class Meta:
> >        model = UserProfilePic
> >        fields = ('profilepic',)
>
> > […]
>
> >    form = UserProfilePicForm(instance=u.get_profile())
>
> u.get_profile() returns a UserProfile. Your form definition says that
> this form is for a UserProfilePic model.
>
> Cheers
>
> Tom

-- 
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: help needed with multiple profile images with UserProfile

2012-02-24 Thread Tom Evans
On Fri, Feb 24, 2012 at 2:20 PM, richard  wrote:
> Hi, Am i doing this in the correct way?
> […]
>
> any help would be greatly appreciated.
>
> […]
>
> from .models import UserProfilePic
> class UserProfilePicForm(ModelForm):
>    class Meta:
>        model = UserProfilePic
>        fields = ('profilepic',)
>
> […]
>
>    form = UserProfilePicForm(instance=u.get_profile())


u.get_profile() returns a UserProfile. Your form definition says that
this form is for a UserProfilePic model.

Cheers

Tom

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



help needed with multiple profile images with UserProfile

2012-02-24 Thread richard
Hi, Am i doing this in the correct way? I am trying to accomplish a
UserProfile having multiple profile images. IE if a user uploads a
profile photo it gets saved as the default profile pic but if they
upload another pic then that becomes the default pic but i need to
keep records of all the profile pics that user has uploaded so that if
they view there profile pics they can see them all. Is this  1 to many
on UserProfile or a ManyToMany? as when i try a 1 to many i cant seem
to get the code working.

any help would be greatly appreciated.


code below.

MODELS.py
from django.contrib.auth.models import User

class UserProfile(models.Model):
user = models.OneToOneField(User)

class UserProfilePic(models.Model):
userprofile = models.ForeignKey(UserProfile)
profilepic = models.ImageField(upload_to='photos')

FORMS.py
from .models import UserProfilePic
class UserProfilePicForm(ModelForm):
class Meta:
model = UserProfilePic
fields = ('profilepic',)

VIEWS.py
def userprofilepic(request):
c = {}
c.update(csrf(request))

u = User.objects.get(pk=1) #just testing with 1 user
form = UserProfilePicForm(instance=u.get_profile())
if request.method == "POST":
form =
UserProfilePicForm(request.POST,request.FILES,instance=u.get_profile())
if form.is_valid():
form.save()
else:
return HttpResponse('failed')
c['form'] = form
return
render_to_response('photo.html',c,context_instance=RequestContext(request))

SQL OUTPUT thats been run on the view which doesnt seem to update
userprofilepic table

{'time': '0.001', 'sql': u'SELECT "auth_user"."id",
"auth_user"."username", "auth_user"."first_name",
"auth_user"."last_name", "auth_user"."email", "auth_user"."password",
"auth_user"."is_staff", "auth_user"."is_active",
"auth_user"."is_superuser", "auth_user"."last_login",
"auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."id" = 1
'}{'time': '0.000', 'sql': u'SELECT "mysite_userprofile"."id",
"mysite_userprofile"."user_id" FROM "mysite_userprofile" WHERE
"mysite_userprofile"."user_id" = 1 '}{'time': '0.000', 'sql': u'SELECT
(1) AS "a" FROM "mysite_userprofile" WHERE "mysite_userprofile"."id" =
1 LIMIT 1'}{'time': '0.001', 'sql': u'UPDATE "mysite_userprofile" SET
"user_id" = 1 WHERE "mysite_userprofile"."id" = 1 '}

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