Django User model

2019-06-24 Thread AMOUSSOU Kenneth
Hi everyone,

Is it possible to create different class that will extend the `User` base 
class with different attributes? And use those class for authentication
Thanks

-- 
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/860ecbae-0492-4f4c-8df3-459b32a46a76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django user model json

2013-02-08 Thread Anderson
Hi guys I have this class that extends from Class User

class UserProfile(User):
#timezone = models.CharField(max_length=50,
default='America/Edmonton')
activation_key   = models.CharField(max_length=40)
key_expires  = models.DateTimeField()
objects = UserManager()

this is the object after UserProfile.objects.get(id=13);

{'_state': ,
 'activation_key': u'52UEOYT8F6EA5Q3K1CXRJMM9PQIFW511DG3H5J',
 'date_joined': datetime.datetime(2013, 2, 8, 16, 59, 4, tzinfo=),
 'email': u'm...@gmail.com',
 'first_name': u'Anderson',
 'id': 13L,
 'is_active': True,
 'is_staff': False,
 'is_superuser': False,
 'key_expires': datetime.datetime(2013, 2, 10, 16, 59, 4, tzinfo=),
 'last_login': datetime.datetime(2013, 2, 8, 17, 0, 37, tzinfo=),
 'last_name': u'',
 'password':
u'pbkdf2_sha256$1$ObXZ2yN3HATp$3ADUPZrzdvQCkPdJPCakfzILAIF8lPbKgAZLiXm54UI=',
 'user_ptr_id': 13L,
 'username': u''}


My problem is when I serialize the object is only showing this.
{
  "user_permissions": [],
  "activation_key": "52UEOYT8F6EA5Q3K1CXRJMM9PQIFW511DG3H5J",
  "groups": [],
  "key_expires": "2013-02-10T16:59:04Z"
}

anyone know why just UserProfile Attributes has been serialized and User
didn't?

this is my function

def serializeModel(objs, mindent=10, mrelations=True):

try:
raw_data =  json.loads(serializers.serialize('json',objs,
ensure_ascii=False,indent=mindent))
return [d['fields'] for d in raw_data]
except:
raw_data = json.loads(serializers.serialize('json',[objs],
ensure_ascii=False,indent=mindent))

return [d['fields'] for d in raw_data][0]




-- 
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 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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Extend django user model

2013-04-16 Thread Laurent David Deschambault
Hi,

I want to extend the existing user model and I have followed the 
instructions found in the Django documentation (
https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model
).
My issue is that my additional fields (which are ForeignKey) cannot be 
blank or null. Even if I set them to blank = false and null = false, the 
admin site will still save the new user without any value attached to these 
additional fields.
Am I missing something here? I thought the admin site wouldn't allow it.

Thanks in advance

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Customising django user model

2019-05-19 Thread Sipum
Hello Friends,

I want to customise django default user table and which should consist of 
name,phone, email and gender.
And after that when every time a user logs in, he/she should able to log in 
through an OTP to phone or email.

can anyone guide me  What to do here.??

Thanks.
Sipum

-- 
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/9b92fdc5-8f36-45e7-809e-b32d4ab41687%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django User model

2019-06-24 Thread Andrew C.
Like a profile? Try this:
https://simpleisbetterthancomplex.com/tutorial/2016/11/23/how-to-add-user-profile-to-django-admin.html

On Mon, Jun 24, 2019 at 9:13 AM AMOUSSOU Kenneth 
wrote:

> Hi everyone,
>
> Is it possible to create different class that will extend the `User` base
> class with different attributes? And use those class for authentication
> Thanks
>
> --
> 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/860ecbae-0492-4f4c-8df3-459b32a46a76%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAJVmkNkY6snPQ-occ1fkDLykX2%2BiyOHd17rMEDVMeqx4W%3DKDyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django User model

2019-06-25 Thread AMOUSSOU Kenneth
Thank you very much!

-- 
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/ad504f3c-ebdc-4a51-b04f-ea951b0f8e39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django user model json

2013-02-08 Thread Jacob Kaplan-Moss
Hi Anderson --

First, I need to point out something:

On Fri, Feb 8, 2013 at 2:07 PM, Anderson  wrote:
>  'password':
> u'pbkdf2_sha256$1$ObXZ2yN3HATp$3ADUPZrzdvQCkPdJPCakfzILAIF8lPbKgAZLiXm54UI=',

You just posted a password -- yours or one of your users -- on a
public mailing list.

PLEASE RESET THIS PASSWORD IMMEDIATELY. Also if this "activation_key"
is anything sensitive, you should scrub it right away. Django uses a
one-way hashing algorithm that partially protects you against leaking
passwords, but given enough time an attacker could reverse what you
just posted.

So once again, you need to reset that password immediately. If it's a
password you use elsewhere, you should reset it everywhere you use it.
If it's one of your users' passwords, you should notify them
immediately.

Sorry if this comes across as harsh, but the consequences here are
potentially disastrous, and I want to make sure you get the severity
and respond immediately.

Now, as to the issue at hand: I think the answer depends on what
version of Django you're using:

* If this is 1.4, this is probably "correct" at least according to
what Django thinks. When you subclass User you're actually creating a
relationship, not a subclassed model, so Django's only serializing the
local fields on your subclass, not following the relationship.

* If this is 1.5, and you're trying to create a custom User model,
you'll want to subclass AbstractBaseUser instead of User; see
https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model
for more details.

Thanks, and again - sorry to be harsh on the security stuff. But it's important!

Jacob

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django user model json

2013-02-08 Thread Anderson
Hi Jacob

thanks for the tip  but don't worry that is just a test script  there are
not real users and is running my local server that doesn't have any outside
connection.
Thanks anyway is always good to be careful.
I am using django 1.4 so you telling me that parents classes cannot be
serialized? humm any ideas how do it?

thank you.


On Fri, Feb 8, 2013 at 8:20 PM, Jacob Kaplan-Moss wrote:

> Hi Anderson --
>
> First, I need to point out something:
>
> On Fri, Feb 8, 2013 at 2:07 PM, Anderson 
> wrote:
> >  'password':
> >
> u'pbkdf2_sha256$1$ObXZ2yN3HATp$3ADUPZrzdvQCkPdJPCakfzILAIF8lPbKgAZLiXm54UI=',
>
> You just posted a password -- yours or one of your users -- on a
> public mailing list.
>
> PLEASE RESET THIS PASSWORD IMMEDIATELY. Also if this "activation_key"
> is anything sensitive, you should scrub it right away. Django uses a
> one-way hashing algorithm that partially protects you against leaking
> passwords, but given enough time an attacker could reverse what you
> just posted.
>
> So once again, you need to reset that password immediately. If it's a
> password you use elsewhere, you should reset it everywhere you use it.
> If it's one of your users' passwords, you should notify them
> immediately.
>
> Sorry if this comes across as harsh, but the consequences here are
> potentially disastrous, and I want to make sure you get the severity
> and respond immediately.
>
> Now, as to the issue at hand: I think the answer depends on what
> version of Django you're using:
>
> * If this is 1.4, this is probably "correct" at least according to
> what Django thinks. When you subclass User you're actually creating a
> relationship, not a subclassed model, so Django's only serializing the
> local fields on your subclass, not following the relationship.
>
> * If this is 1.5, and you're trying to create a custom User model,
> you'll want to subclass AbstractBaseUser instead of User; see
>
> https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model
> for more details.
>
> Thanks, and again - sorry to be harsh on the security stuff. But it's
> important!
>
> Jacob
>
> --
> 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 http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


-- 
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 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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Customising django user model

2019-05-20 Thread Rafael E. Ferrero
Hello, you must to extend User model... search on google with this
aproach!!

Cheers!

Rafael E. Ferrero


El dom., 19 may. 2019 a las 14:13, Sipum () escribió:

> Hello Friends,
>
> I want to customise django default user table and which should consist of
> name,phone, email and gender.
> And after that when every time a user logs in, he/she should able to log
> in through an OTP to phone or email.
>
> can anyone guide me  What to do here.??
>
> Thanks.
> Sipum
>
> --
> 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/9b92fdc5-8f36-45e7-809e-b32d4ab41687%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAJJc_8XYD7zGAOmaezmS_sGoDr5R0gz1Y44y6ED-sn-dxzj02A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customising django user model

2019-05-20 Thread Sipum Mishra
Ok thanks for reply.

On Mon, 20 May, 2019, 5:36 PM Rafael E. Ferrero, 
wrote:

> Hello, you must to extend User model... search on google with this
> aproach!!
>
> Cheers!
>
> Rafael E. Ferrero
>
>
> El dom., 19 may. 2019 a las 14:13, Sipum () escribió:
>
>> Hello Friends,
>>
>> I want to customise django default user table and which should consist of
>> name,phone, email and gender.
>> And after that when every time a user logs in, he/she should able to log
>> in through an OTP to phone or email.
>>
>> can anyone guide me  What to do here.??
>>
>> Thanks.
>> Sipum
>>
>> --
>> 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/9b92fdc5-8f36-45e7-809e-b32d4ab41687%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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/CAJJc_8XYD7zGAOmaezmS_sGoDr5R0gz1Y44y6ED-sn-dxzj02A%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGHZBzyygP31OdejPiNn7V_KtYprD5kfswBeJMbD1y2zesmuOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customising django user model

2019-05-20 Thread Joe Reitman
You can customize the user table by extending AbstractUser and add the 
fields you want to add (gender, phone)

I have a custom user example adding age field:

from django.db import models
from django.contrib.auth.models import AbstractUser

class CustomUser(AbstractUser):
   age = models.PositiveIntegerField(null=True, blank=True) 


On Sunday, May 19, 2019 at 12:13:08 PM UTC-5, Sipum wrote:
>
> Hello Friends,
>
> I want to customise django default user table and which should consist of 
> name,phone, email and gender.
> And after that when every time a user logs in, he/she should able to log 
> in through an OTP to phone or email.
>
> can anyone guide me  What to do here.??
>
> Thanks.
> Sipum
>

-- 
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/24afe883-98b9-4bfc-a9fe-284c7a6cb771%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customising django user model

2019-05-20 Thread mahesh boini
Extend AbstractUser class and give that name in settings file like
AUTH_USER_MODEL=‘appname.modelname’

On Tue, 21 May 2019 at 05:51, Joe Reitman  wrote:

> You can customize the user table by extending AbstractUser and add the
> fields you want to add (gender, phone)
>
> I have a custom user example adding age field:
>
> from django.db import models
> from django.contrib.auth.models import AbstractUser
>
> class CustomUser(AbstractUser):
>age = models.PositiveIntegerField(null=True, blank=True)
>
>
> On Sunday, May 19, 2019 at 12:13:08 PM UTC-5, Sipum wrote:
>>
>> Hello Friends,
>>
>> I want to customise django default user table and which should consist of
>> name,phone, email and gender.
>> And after that when every time a user logs in, he/she should able to log
>> in through an OTP to phone or email.
>>
>> can anyone guide me  What to do here.??
>>
>> Thanks.
>> Sipum
>>
> --
> 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/24afe883-98b9-4bfc-a9fe-284c7a6cb771%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CANR2ZjviAk_hCz%2BVum2kUa7vo6SJP8ZCuOsg0cH9uLncL_mDBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customising django user model

2019-05-20 Thread Sipum Mishra
Thanks a lot.. @Joe @Mahes
It will help me a lot.

On Tue, 21 May, 2019, 8:14 AM mahesh boini, 
wrote:

> Extend AbstractUser class and give that name in settings file like
> AUTH_USER_MODEL=‘appname.modelname’
>
> On Tue, 21 May 2019 at 05:51, Joe Reitman  wrote:
>
>> You can customize the user table by extending AbstractUser and add the
>> fields you want to add (gender, phone)
>>
>> I have a custom user example adding age field:
>>
>> from django.db import models
>> from django.contrib.auth.models import AbstractUser
>>
>> class CustomUser(AbstractUser):
>>age = models.PositiveIntegerField(null=True, blank=True)
>>
>>
>> On Sunday, May 19, 2019 at 12:13:08 PM UTC-5, Sipum wrote:
>>>
>>> Hello Friends,
>>>
>>> I want to customise django default user table and which should consist
>>> of name,phone, email and gender.
>>> And after that when every time a user logs in, he/she should able to log
>>> in through an OTP to phone or email.
>>>
>>> can anyone guide me  What to do here.??
>>>
>>> Thanks.
>>> Sipum
>>>
>> --
>> 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/24afe883-98b9-4bfc-a9fe-284c7a6cb771%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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/CANR2ZjviAk_hCz%2BVum2kUa7vo6SJP8ZCuOsg0cH9uLncL_mDBQ%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAGHZBzzNHg4-Xkn5aGVRpttxBZooKy1DSS_SGNU5gbUdW7FCYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customising django user model

2019-05-22 Thread אורי
Hi Sipum,

We did it on Speedy Net and you can see our models and settings there:

https://github.com/speedy-net/speedy-net
https://github.com/speedy-net/speedy-net/blob/master/speedy/core/accounts/models.py#L160
https://github.com/speedy-net/speedy-net/blob/master/speedy/core/settings/base_with_login.py#L26


אורי
u...@speedy.net


On Sun, May 19, 2019 at 8:13 PM Sipum  wrote:

> Hello Friends,
>
> I want to customise django default user table and which should consist of
> name,phone, email and gender.
> And after that when every time a user logs in, he/she should able to log
> in through an OTP to phone or email.
>
> can anyone guide me  What to do here.??
>
> Thanks.
> Sipum
>
> --
> 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/9b92fdc5-8f36-45e7-809e-b32d4ab41687%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CABD5YeFBbZ%3Df2xPYNWZY%3D_FHWGK0eUeDm9W8NDonKTOT1DVWhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Extending Django User model using add_to_class()

2009-06-22 Thread pr

Hi,

Is it a good way to extend Django User model using add_to_class()?
I have to add only two extra fields to the User model and I think that
using Profile Model to do this is unnecessary.

My way:

# Accounts models.py
User.add_to_class('field1', models.CharField(max_length=255))
User.add_to_class('field2', models.CharField(max_length=255))

# Accounts admin.py

class CustomUserAdmin(UserAdmin):
fieldsets = (
(None, {'fields': ('username', 'password')}),
(_('Personal info'), {'fields': ('email',)}),
(_('Permissions'), {'fields': ('is_staff', 'is_active',
'is_superuser', 'user_permissions')}),
(_('Important dates'), {'fields': ('last_login',
'date_joined')}),
(_('Groups'), {'fields': ('groups',)}),
(_('MyExtraFields'), {'fields': ('field1', 'field2')}),
)

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

Finally:
> python manage.py syncdb

Thank You,
regards.
--~--~-~--~~~---~--~~
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: Extending Django User model using add_to_class()

2009-06-22 Thread James Bennett

On Mon, Jun 22, 2009 at 4:01 PM, pr wrote:
> Is it a good way to extend Django User model using add_to_class()?
> I have to add only two extra fields to the User model and I think that
> using Profile Model to do this is unnecessary.

No, it's a very bad method. Consider what happens if two people want
to add fields of the same name; trying to stick them in the User model
will obviously fail and break at least one person's code. Using the
standard method of a related profile model keeps them neatly
namespaced.

As a general rule, consider code in other people's applications
(including applications in django.contrib) to be read-only.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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: Extending Django User model using add_to_class()

2009-06-22 Thread pr

On 22 Cze, 23:14, James Bennett  wrote:
> No, it's a very bad method. Consider what happens if two people want
> to add fields of the same name; trying to stick them in the User model
> will obviously fail and break at least one person's code.
Yes, I know what you mean, but It's small project with one programmer.
I want to know about speed and stability in production mode above
rules of 'programming-tao' :-)

regards.
--~--~-~--~~~---~--~~
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: Extending Django User model using add_to_class()

2009-06-22 Thread James Bennett

On Mon, Jun 22, 2009 at 5:30 PM, pr wrote:
> Yes, I know what you mean, but It's small project with one programmer.
> I want to know about speed and stability in production mode above
> rules of 'programming-tao' :-)

Well, there's also the fact that:

1. Using a profile means relying on documented, guaranteed-stable
behavior in Django.
2. Using the add_to_class trick means relying on undocumented
internals which have no stability guarantee whatsoever, and which are
subject to change without warning.

Seriously: there's a documented and supported method for storing
additional information related to users. Please take advantage of it.

(and, really I speak from experience regarding other ways to do this;
I have hacked up Django in just about every way possible, and I
remember back when you could do things like outright replace models
with your own definitions, and all of it was a freaking nightmare for
maintainability)


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



Extending django User model to multiple profiles

2007-04-18 Thread checco

Hi,

from here, as you certainly know, you can see how to extend the User
model to fit the particular needs of a given application:
http://www.b-list.org/weblog/2006/06/06/django-tips-extending-user-model

In my application I have two different kind of users, so I have to
extend it twice: which value should I specify for the parameter
AUTH_PROFILE_MODULE in settings.py?

Thanks and regards
Francesco


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



Extending Django User model with django-allauth

2019-01-28 Thread Achyut Pandey
I'm using django-allauth and I want to be able to add new field to my User
model. What's the best way to do this as of you ?

-- 
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/CAPHSfHWaDi3uP1daazVbpSgeMBvEkLNKC-osvu-qKD2jYfbrDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Extending and Entity with the Django User model

2010-05-12 Thread x13
Hello, I need to extend the Django User model in this way: I have an
Entity model an I want to define a relationship one-2-one from User to
Entity (so a Django User can be an Entity, but an Entity can be
something else).


So what's the best way to extend the User model for this particular
case??

I've read the 'official' ways to extend Django User model
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

and the Django book's way too:
http://www.djangobook.com/en/1.0/chapter12/#cn222

Iv'e read this one too
http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/

but can't decide on which one is the best for my case. The problem is
that I don't want to extend the User with a custom profile, I want to
extend my custom Entity model with User model, something like that
maybe works:

class MyUser(models.Model):
user = models.ForeignKey(User, unique=True)
entity = models.ForeignKey(Entity, unique=True)


Any opinions? Thanks in advance.
x13






-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Extending and Entity with the Django User model

2010-05-12 Thread x13
> something like that maybe works:
>
> class MyUser(models.Model):
>     user = models.ForeignKey(User, unique=True)
>     entity = models.ForeignKey(Entity, unique=True)
>     
>

Sorry, this is my current proposal (but I really don't know if there
is some difference with the previous one):

class MyUser(models.Model):
    user = models.ForeignKey(User, unique=True)
    entity = models.OneToOneField(Entity, primary_key=True)
    


cheers,
x13

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.



Need help in Django User Model customization and authentication

2017-05-13 Thread Ajat Prabha


Hello everyone,
I'm creating a payment gateway to make transactions on my college campus go 
cashless. It can be used to pay library dues, stationary charges, etc. The 
user will add money to a central account and then he/she can use that money 
virtually. I chose Django because of its security. But as I need 3 groups 
of users viz. Faculty, Student and Staff, I'm having trouble to implement 
this in the best possible way. I fix one thing, the other gets disturbed. 
I'm new to Django, so I don't have much experience. I'm comfortable with 
views, basic models, etc. But this User customization, I can't get it right.

I'm attaching a representational User model (any suggestions are welcome), 
please have a look. All the 3 groups will have certain fields common and 
certain fields specific to that group only like roll_number/employee_code 
and permission_sets(in case the system is later used for access to labs, 
etc.). The fields at below of the image will be common to all groups.



I also tried this 
 customization 
which 
worked but then I had issues in Django admin view where the password was 
stored in plain hashed value. I think it has something to do with 
reimplementing ReadOnlyPasswordHashWidget method declared in 
django.contrib.auth.forms but I'm not sure!

I chose Django in the first place for security reasons and I'm not able to 
get it right.
Can someone please help me out.

Thanks!

-- 
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/a98d6c25-68e0-49f6-acf1-1267e610281a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Migrating from django user model to a custom user model

2017-03-14 Thread Kakar Nyori


I am following these two references (one 
<https://code.djangoproject.com/ticket/25313> and two 
<http://django-authtools.readthedocs.io/en/latest/how-to/migrate-to-a-custom-user-model.html>)
 
to have a custom user model in order to authenticate via email and also to 
add an extra field to it.


class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(
unique=True,
max_length=254,
)
mobile_number = models.IntegerField(unique=True)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

objects = UserManager()
...
...
class Meta:
db_table = 'auth_user'
...
...


As you can see, I have added the db_table='auth_user' into the Meta fields 
of the class. Also, I have included AUTH_USER_MODEL = 'accounts.User' and 
the User model app (i.e., accounts) into the INSTALLED_APPS in settings.py. 
Further more, I deleted the migrations folder from the app.


Then tried migrating:

$ python manage.py makemigrations accountsMigrations for 'accounts':
  accounts/migrations/0001_initial.py:
- Create model User

$ python manage.py migrate accounts

Which gives me an error:

django.db.migrations.exceptions.InconsistentMigrationHistory: Migration 
admin.0001_initial is applied before its dependency accounts.0001_initial 
on database 'default'.

How can I migrate from the existing django user model into a custom user 
model? Could you guys please help me out.


Thank you

-- 
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/4acb65c3-04a2-47b8-8a51-fbb0ec587f37%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need help in Django User Model customization and authentication

2017-05-13 Thread Constantine Covtushenko
Hi Ajat,

It was not clear to me why you do not use 'Extending the existing User
model' approach, described here

.

For me it works very well in almost all cases.
And if you go that way then authentication/authorization based questions
should not bring any worries at all.

But may be I missed something.
If so, please provide us with more concrete questions.

Regards,
Constantine C.

On Sat, May 13, 2017 at 4:23 PM, Ajat Prabha 
wrote:

> Hello everyone,
> I'm creating a payment gateway to make transactions on my college campus
> go cashless. It can be used to pay library dues, stationary charges, etc.
> The user will add money to a central account and then he/she can use that
> money virtually. I chose Django because of its security. But as I need 3
> groups of users viz. Faculty, Student and Staff, I'm having trouble to
> implement this in the best possible way. I fix one thing, the other gets
> disturbed. I'm new to Django, so I don't have much experience. I'm
> comfortable with views, basic models, etc. But this User customization, I
> can't get it right.
>
> I'm attaching a representational User model (any suggestions are welcome),
> please have a look. All the 3 groups will have certain fields common and
> certain fields specific to that group only like roll_number/employee_code
> and permission_sets(in case the system is later used for access to labs,
> etc.). The fields at below of the image will be common to all groups.
>
>
> 
>
> I also tried this
>  customization 
> which
> worked but then I had issues in Django admin view where the password was
> stored in plain hashed value. I think it has something to do with
> reimplementing ReadOnlyPasswordHashWidget method declared in
> django.contrib.auth.forms but I'm not sure!
>
> I chose Django in the first place for security reasons and I'm not able to
> get it right.
> Can someone please help me out.
>
> Thanks!
>
> --
> 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/a98d6c25-68e0-49f6-acf1-1267e610281a%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Sincerely yours,
Constantine C

-- 
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/CAK52boU%3D339EOU2L33EAg-jeNPPE%3Dm%2Bp1_ouQH4kx0ivJVO_8g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need help in Django User Model customization and authentication

2017-05-14 Thread Scot Hacker
This is a fairly common need in academia, where your users need a different 
set of profile fields depending on affiliation. And you always end up with 
edge cases where some people are simultaneously faculty and staff, or even 
student and faculty, etc. And those "special" people will need to have all 
of the right fields available to them.  You could take an approach 
something like this:

- Set up standard Groups for Students, Faculty, Staff (and maybe Alumni)
- Have a management command or import script that ensures everyone is in 
all the right groups
- Set up a shared UserProfile model that includes all shared fields
- For convenience, set up model methods on UserProfile that determine a 
person's status based on group membership, e.g. `is_faculty()`, 
`is_student()` etc. (taking care to not interfere with Django' built-in 
`is_staff` boolean!). This way you can do quick affiliation checks from 
anywhere (e.g. in templates)
- Set up additional FacultyProfile, StudentProfile, StaffProfile classes 
with the unique fields and with ForeignKeys to UserProfile
- Either in your import scripts or in save() method or elsewhere, 
instantiate the additional profile classes:

if user.is_faculty():
  fac_profile = FacultyProfile.objects.get_or_create(user=self)

That's very loose and there are many ways to go about it, but that's one 
possible approach.  Another would be to simply put *all* possible fields on 
UserProfile and just populate them based on affiliation. That's not very 
clean though, because if someone stops being faculty for instance, it would 
be tricky to ensure you remove all of the right field data (it's messy). So 
 season to taste.

./s

On Saturday, May 13, 2017 at 7:32:27 AM UTC-7, Ajat Prabha wrote:
>
> Hello everyone,
> I'm creating a payment gateway to make transactions on my college campus 
> go cashless. It can be used to pay library dues, stationary charges, etc. 
> The user will add money to a central account and then he/she can use that 
> money virtually. I chose Django because of its security. But as I need 3 
> groups of users viz. Faculty, Student and Staff, I'm having trouble to 
> implement this in the best possible way. I fix one thing, the other gets 
> disturbed. I'm new to Django, so I don't have much experience. I'm 
> comfortable with views, basic models, etc. But this User customization, I 
> can't get it right.
>
> I'm attaching a representational User model (any suggestions are welcome), 
> please have a look. All the 3 groups will have certain fields common and 
> certain fields specific to that group only like roll_number/employee_code 
> and permission_sets(in case the system is later used for access to labs, 
> etc.). The fields at below of the image will be common to all groups.
>
>
> 
>
> I also tried this 
>  customization 
> which 
> worked but then I had issues in Django admin view where the password was 
> stored in plain hashed value. I think it has something to do with 
> reimplementing ReadOnlyPasswordHashWidget method declared in 
> django.contrib.auth.forms but I'm not sure!
>
> I chose Django in the first place for security reasons and I'm not able to 
> get it right.
> Can someone please help me out.
>
> Thanks!
>

-- 
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/0c767ab1-5742-4441-8e57-fdb828325f68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need help in Django User Model customization and authentication

2017-05-18 Thread Ajat Prabha
Thanks for your reply, actually I need two passwords, one being normal 
alphanumeric and other being PIN-based with proper validation and features 
provided by Django auth core. Is it possible to do that with just extending 
User model?

On Saturday, 13 May 2017 23:59:14 UTC+5:30, Constantine Covtushenko wrote:
>
> Hi Ajat,
>
> It was not clear to me why you do not use 'Extending the existing User 
> model' approach, described here 
> 
> .
>
> For me it works very well in almost all cases.
> And if you go that way then authentication/authorization based questions 
> should not bring any worries at all.
>
> But may be I missed something.
> If so, please provide us with more concrete questions.
>
> Regards,
> Constantine C.
>
> On Sat, May 13, 2017 at 4:23 PM, Ajat Prabha  > wrote:
>
>> Hello everyone,
>> I'm creating a payment gateway to make transactions on my college campus 
>> go cashless. It can be used to pay library dues, stationary charges, etc. 
>> The user will add money to a central account and then he/she can use that 
>> money virtually. I chose Django because of its security. But as I need 3 
>> groups of users viz. Faculty, Student and Staff, I'm having trouble to 
>> implement this in the best possible way. I fix one thing, the other gets 
>> disturbed. I'm new to Django, so I don't have much experience. I'm 
>> comfortable with views, basic models, etc. But this User customization, I 
>> can't get it right.
>>
>> I'm attaching a representational User model (any suggestions are 
>> welcome), please have a look. All the 3 groups will have certain fields 
>> common and certain fields specific to that group only like 
>> roll_number/employee_code and permission_sets(in case the system is later 
>> used for access to labs, etc.). The fields at below of the image will be 
>> common to all groups.
>>
>>
>> 
>>
>> I also tried this 
>>  
>> customization which 
>> worked but then I had issues in Django admin view where the password was 
>> stored in plain hashed value. I think it has something to do with 
>> reimplementing ReadOnlyPasswordHashWidget method declared in 
>> django.contrib.auth.forms but I'm not sure!
>>
>> I chose Django in the first place for security reasons and I'm not able 
>> to get it right.
>> Can someone please help me out.
>>
>> Thanks!
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/a98d6c25-68e0-49f6-acf1-1267e610281a%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Sincerely yours,
> Constantine C
>

-- 
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/1585918f-33a1-489c-b03d-3a1cd2b9bdc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need help in Django User Model customization and authentication

2017-05-18 Thread Ajat Prabha
Thanks for the reply, Scot, I've some questions here:

   1. Is setting up groups necessary if I'm creating shared UserProfile? If 
   not, will groups be anyhow beneficial to this new setup?
   2. Shall I create shared UserProfile from User? If yes, how can I handle 
   the need for two passwords, one being normal alphanumeric for normal 
   dashboard login and one being PIN-based for transactions with validation 
   and security like Django's auth package?
   3. Could you please elaborate/explain the need for this or maybe how is 
   this useful:
   
>Either in your import scripts or in save() method or elsewhere, 
>instantiate the additional profile classes:
>if user.is_faculty():
>  fac_profile = FacultyProfile.objects.get_or_create(user=self) 
   

   
Thanks! 

>
On Sunday, 14 May 2017 22:15:25 UTC+5:30, Scot Hacker wrote:
>
> This is a fairly common need in academia, where your users need a 
> different set of profile fields depending on affiliation. And you always 
> end up with edge cases where some people are simultaneously faculty and 
> staff, or even student and faculty, etc. And those "special" people will 
> need to have all of the right fields available to them.  You could take an 
> approach something like this:
>
> - Set up standard Groups for Students, Faculty, Staff (and maybe Alumni)
> - Have a management command or import script that ensures everyone is in 
> all the right groups
> - Set up a shared UserProfile model that includes all shared fields
> - For convenience, set up model methods on UserProfile that determine a 
> person's status based on group membership, e.g. `is_faculty()`, 
> `is_student()` etc. (taking care to not interfere with Django' built-in 
> `is_staff` boolean!). This way you can do quick affiliation checks from 
> anywhere (e.g. in templates)
> - Set up additional FacultyProfile, StudentProfile, StaffProfile classes 
> with the unique fields and with ForeignKeys to UserProfile
> - Either in your import scripts or in save() method or elsewhere, 
> instantiate the additional profile classes:
>
> if user.is_faculty():
>   fac_profile = FacultyProfile.objects.get_or_create(user=self)
>
> That's very loose and there are many ways to go about it, but that's one 
> possible approach.  Another would be to simply put *all* possible fields on 
> UserProfile and just populate them based on affiliation. That's not very 
> clean though, because if someone stops being faculty for instance, it would 
> be tricky to ensure you remove all of the right field data (it's messy). So 
>  season to taste.
>
> ./s
>
> On Saturday, May 13, 2017 at 7:32:27 AM UTC-7, Ajat Prabha wrote:
>>
>> Hello everyone,
>> I'm creating a payment gateway to make transactions on my college campus 
>> go cashless. It can be used to pay library dues, stationary charges, etc. 
>> The user will add money to a central account and then he/she can use that 
>> money virtually. I chose Django because of its security. But as I need 3 
>> groups of users viz. Faculty, Student and Staff, I'm having trouble to 
>> implement this in the best possible way. I fix one thing, the other gets 
>> disturbed. I'm new to Django, so I don't have much experience. I'm 
>> comfortable with views, basic models, etc. But this User customization, I 
>> can't get it right.
>>
>> I'm attaching a representational User model (any suggestions are 
>> welcome), please have a look. All the 3 groups will have certain fields 
>> common and certain fields specific to that group only like 
>> roll_number/employee_code and permission_sets(in case the system is later 
>> used for access to labs, etc.). The fields at below of the image will be 
>> common to all groups.
>>
>>
>> 
>>
>> I also tried this 
>>  
>> customization which 
>> worked but then I had issues in Django admin view where the password was 
>> stored in plain hashed value. I think it has something to do with 
>> reimplementing ReadOnlyPasswordHashWidget method declared in 
>> django.contrib.auth.forms but I'm not sure!
>>
>> I chose Django in the first place for security reasons and I'm not able 
>> to get it right.
>> Can someone please help me out.
>>
>> Thanks!
>>
>

-- 
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/fc428b51-5b76-4206-9f87-66c2011b2d0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrating from django user model to a custom user model

2017-03-15 Thread Tim Graham
You can find an overview of how to migrate to a custom user model in 
https://code.djangoproject.com/ticket/25313.

On Tuesday, March 14, 2017 at 11:42:34 PM UTC-4, Kakar Nyori wrote:
>
> I am following these two references (one 
> <https://code.djangoproject.com/ticket/25313> and two 
> <http://django-authtools.readthedocs.io/en/latest/how-to/migrate-to-a-custom-user-model.html>)
>  
> to have a custom user model in order to authenticate via email and also to 
> add an extra field to it.
>
>
> class User(AbstractBaseUser, PermissionsMixin):
> email = models.EmailField(
> unique=True,
> max_length=254,
> )
> mobile_number = models.IntegerField(unique=True)
> is_active = models.BooleanField(default=True)
> is_admin = models.BooleanField(default=False)
>
> objects = UserManager()
> ...
> ...
> class Meta:
> db_table = 'auth_user'
> ...
> ...
>
>
> As you can see, I have added the db_table='auth_user' into the Meta 
> fields of the class. Also, I have included AUTH_USER_MODEL = 
> 'accounts.User' and the User model app (i.e., accounts) into the 
> INSTALLED_APPS in settings.py. Further more, I deleted the migrations 
> folder from the app.
>
>
> Then tried migrating:
>
> $ python manage.py makemigrations accountsMigrations for 'accounts':
>   accounts/migrations/0001_initial.py:
> - Create model User
>
> $ python manage.py migrate accounts
>
> Which gives me an error:
>
> django.db.migrations.exceptions.InconsistentMigrationHistory: Migration 
> admin.0001_initial is applied before its dependency accounts.0001_initial 
> on database 'default'.
>
> How can I migrate from the existing django user model into a custom user 
> model? Could you guys please help me out.
>
>
> Thank you
>

-- 
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/a111086c-16f2-48b3-9c47-0f0a28bb34d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django User Model one-to-one with other model and Forms

2015-12-07 Thread Emad Mokhtar


I want to create a model for teachers and he will has a user to login to 
the system. I implemented this by one-to-one relation between Teacher model 
and User model, but I can't get my head around making a form for Teacher 
model and in the same time I want to create user for him/her, please note 
I'm using CreateView generic view.
models.py

class Teacher(models.Model):
GENDER_CHOICES = (
(MALE, _('Male')),
(FEMALE, _('Female')),
)
gender = models.CharField(max_length=1, verbose_name=_('Gender'),
  choices=GENDER_CHOICES)
civil_id = models.CharField(max_length=12, verbose_name=_('Civil ID'))
phone_number = models.CharField(max_length=15,
verbose_name=_('Phone Number'))
job_title = models.CharField(max_length=15, verbose_name=_('Title'))
user = models.OneToOneField(to=User, related_name='teacher_profile')

def enable(self):
"""
Enable teacher profile
:return:
"""
self.user.is_active = True
self.user.save()

def disable(self):
"""
Disable teacher profile
:return:
"""
self.user.is_active = False
self.user.save()

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7bab5925-e2ec-408b-94ca-6a63f419243c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


New to Django: Please Help!! Django User Model not saving first_name, last_name and email - Authentication App

2018-10-29 Thread Adrian Chipukuma
Hello,

I am new to Django and enjoying the learning process, unfortunately I am
stuck, and I need expert guidance.
I am learning through developing a User Authentication System. The system
is supposed to have a user registration functionality, login, user profile
editing and logout. I have managed to create the login, logout
functionalities and the registration functionality partly. The problem is
on the registration, I am only able to save the 'username and password '
using django forms, I have written the code for saving the first_name and
the last _name as well as email but it seems not to be working, only the
'username and password' are saved.. I think I am missing something though
no error comes up. Please anyone to guide me. Thank you.
the code is as shown below:


views.py
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.contrib import auth, messages
from django.contrib.auth.forms import UserCreationForm
from django import forms
from .forms import SignUpForm

def home(request):
return render(request, 'authenticate/home.html', {})

def login_user(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
messages.success(request,('You have been logged in'))
return redirect('home')
else:
messages.success(request,('Error Logging in!'))
return redirect('login')
else:
return render(request, 'authenticate/login.html', {})

def logout_user(request):
"""if request.method =='POST':"""
logout(request)
messages.success(request,('You have been logged out'))
return redirect('home')

def register_user(request):
if request.method =='POST':
form = SignUpForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
user = authenticate(username=username, password=password)
login(request, user)
messages.success(request,(' Successfully Registered!'))
return redirect('home')
else:
form = SignUpForm()

context = {'form': form }
return render(request, 'authenticate/register.html', context)

urls.py

from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name="home"),
path('login/', views.login_user, name="login"),
path('logout/', views.logout_user, name='logout'),
path('register/', views.register_user, name='register'),
]

forms.py
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.models import User
from django import forms

class SignUpForm(UserCreationForm):
email = forms.EmailField()
first_name = forms.CharField(max_length=100,)
last_name = forms.CharField(max_length=100,)
class meta():
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1',
'password2', )

register.html
{% extends 'authenticate/base.html'%}
{% block content%}
This is the Registration Page

{% csrf_token %}
{% if form.errors %}
Your form has errors
{{ error }}
{% endif %}

{{ form.as_p }}




{% endblock %}


Chao!

Adrian

-- 
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/CAHBk_LKtZ7VP1BrKv_HFYckBAqM%2BMWwjv5WJKjx9bpYkNLd3tw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django user model. 1 admin account, 1 customer account with the same email and different password

2020-04-12 Thread Kenny Soh


Im trying to handle a use case where i have 2 roles. (admin , customer)

There will be an admin portal and a customer portal (2 different login 
pages ).

   - An admin can invite a customer
   - An admin can be a customer as well , can invite himself into the 
   customer portal
   - An admin account must not share the same password as the customer 
   account.
   - Email is used as the unique field for both admin and customer account.

For example :

Admin account - custo...@email.com /password1 
Customer account - custo...@email.com /password2

Solution 1: - Permission. Having 1 account with admin permission and 
customer permission. (This cant work to fit the business use case)

Based on this article: 
https://simpleisbetterthancomplex.com/tutorial/2018/01/18/how-to-implement-multiple-user-types-with-django.html

Solution 2: - Creating 2 django projects. One for each user model since 
both accounts cant share password. The reason for separating into 2 
projects is because resources such as session,login, logout will not be 
shared. So each portal(admin,customer) has their own resource.

   - 
   
   A create Customer API to allow admin to create a customer account in 
   customer django project.
   - 
   
   A shared db to share related data
   
This is the only way i can think of to handle the use case. Please let me 
know if anyone has a better idea to handle this.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/181ec499-e36c-4009-9587-06386219ab8d%40googlegroups.com.


Re: New to Django: Please Help!! Django User Model not saving first_name, last_name and email - Authentication App

2018-10-29 Thread Manjunath
Remove declaration of first_name, last_name & email in Form calss.
class SignUpForm(UserCreationForm):
class meta():
model = User 
fields = ('username', 'first_name', 'last_name', 'email', 
'password1', 'password2', )

 And while Saving the form, follow below steps.
if form.is_valid():
   new_user = form.save(commit=False)
   new_user.set_password(form.cleaned_data['password1'])
  new_user.save()
  # Your next steps


I think you might need to declare password1 & password2 fields in your 
Form. Do Check.



On Monday, October 29, 2018 at 10:04:39 PM UTC+5:30, Adrian Chipukuma wrote:
>
> Hello, 
>
> I am new to Django and enjoying the learning process, unfortunately I am 
> stuck, and I need expert guidance. 
> I am learning through developing a User Authentication System. The system 
> is supposed to have a user registration functionality, login, user profile 
> editing and logout. I have managed to create the login, logout 
> functionalities and the registration functionality partly. The problem is 
> on the registration, I am only able to save the 'username and password ' 
> using django forms, I have written the code for saving the first_name and 
> the last _name as well as email but it seems not to be working, only the 
> 'username and password' are saved.. I think I am missing something though 
> no error comes up. Please anyone to guide me. Thank you.
> the code is as shown below:
>
>
> views.py
> from django.shortcuts import render, redirect
> from django.contrib.auth import authenticate, login, logout
> from django.contrib.auth.models import User
> from django.contrib import auth, messages
> from django.contrib.auth.forms import UserCreationForm
> from django import forms
> from .forms import SignUpForm
>
> def home(request):
> return render(request, 'authenticate/home.html', {})
>
> def login_user(request):
> if request.method == 'POST':
> username = request.POST['username']
> password = request.POST['password']
> user = authenticate(request, username=username, password=password)
> if user is not None:
> login(request, user)
> messages.success(request,('You have been logged in'))
> return redirect('home')
> else:
> messages.success(request,('Error Logging in!'))
> return redirect('login')
> else:
> return render(request, 'authenticate/login.html', {})
>
> def logout_user(request):
> """if request.method =='POST':"""
> logout(request)
> messages.success(request,('You have been logged out'))
> return redirect('home')
>
> def register_user(request):
> if request.method =='POST':
> form = SignUpForm(request.POST)
> if form.is_valid():
> form.save()
> username = form.cleaned_data['username']
> password = form.cleaned_data['password1']
> user = authenticate(username=username, password=password)
> login(request, user)
> messages.success(request,(' Successfully Registered!'))
> return redirect('home')
> else:
> form = SignUpForm()
>
> context = {'form': form }
> return render(request, 'authenticate/register.html', context)
>
> urls.py
>
> from django.urls import path
> from . import views
> urlpatterns = [
> path('', views.home, name="home"),
> path('login/', views.login_user, name="login"),
> path('logout/', views.logout_user, name='logout'),
> path('register/', views.register_user, name='register'),
> ]
>
> forms.py
> from django.contrib.auth.forms import UserCreationForm, UserChangeForm
> from django.contrib.auth.models import User
> from django import forms
>
> class SignUpForm(UserCreationForm):
> email = forms.EmailField()
> first_name = forms.CharField(max_length=100,)
> last_name = forms.CharField(max_length=100,)
> class meta():
> model = User 
> fields = ('username', 'first_name', 'last_name', 'email', 'password1', 
> 'password2', )
>
> register.html
> {% extends 'authenticate/base.html'%}
> {% block content%}
> This is the Registration Page
> 
> {% csrf_token %}
> {% if form.errors %}
> Your form has errors
> {{ error }}
> {% endif %}
> 
> {{ form.as_p }}
> 
> 
> 
> 
> {% endblock %}
>
>
> Chao!
>
> Adrian
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

-- 
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/9a58de45-95d1-4fc6-8948-0cc6994c85fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django: Please Help!! Django User Model not saving first_name, last_name and email - Authentication App

2018-10-30 Thread Adrian Chipukuma
Thanks  for the help.  Though if I  remove  the declarations of the
first_name, last_name and email. Then  I will  not be able to see these  in
the Register form.. The fields password1 and password2 are just working
well and can be saved...  The issue  is on the  first_name, last_name and
email fields...  I can't save them using  the django form..

On Tue, Oct 30, 2018, 7:49 AM Manjunath  wrote:

> Remove declaration of first_name, last_name & email in Form calss.
> class SignUpForm(UserCreationForm):
> class meta():
> model = User
> fields = ('username', 'first_name', 'last_name', 'email',
> 'password1', 'password2', )
>
>  And while Saving the form, follow below steps.
> if form.is_valid():
>new_user = form.save(commit=False)
>new_user.set_password(form.cleaned_data['password1'])
>   new_user.save()
>   # Your next steps
>
>
> I think you might need to declare password1 & password2 fields in your
> Form. Do Check.
>
>
>
> On Monday, October 29, 2018 at 10:04:39 PM UTC+5:30, Adrian Chipukuma
> wrote:
>>
>> Hello,
>>
>> I am new to Django and enjoying the learning process, unfortunately I am
>> stuck, and I need expert guidance.
>> I am learning through developing a User Authentication System. The system
>> is supposed to have a user registration functionality, login, user profile
>> editing and logout. I have managed to create the login, logout
>> functionalities and the registration functionality partly. The problem is
>> on the registration, I am only able to save the 'username and password '
>> using django forms, I have written the code for saving the first_name and
>> the last _name as well as email but it seems not to be working, only the
>> 'username and password' are saved.. I think I am missing something though
>> no error comes up. Please anyone to guide me. Thank you.
>> the code is as shown below:
>>
>>
>> views.py
>> from django.shortcuts import render, redirect
>> from django.contrib.auth import authenticate, login, logout
>> from django.contrib.auth.models import User
>> from django.contrib import auth, messages
>> from django.contrib.auth.forms import UserCreationForm
>> from django import forms
>> from .forms import SignUpForm
>>
>> def home(request):
>> return render(request, 'authenticate/home.html', {})
>>
>> def login_user(request):
>> if request.method == 'POST':
>> username = request.POST['username']
>> password = request.POST['password']
>> user = authenticate(request, username=username, password=password)
>> if user is not None:
>> login(request, user)
>> messages.success(request,('You have been logged in'))
>> return redirect('home')
>> else:
>> messages.success(request,('Error Logging in!'))
>> return redirect('login')
>> else:
>> return render(request, 'authenticate/login.html', {})
>>
>> def logout_user(request):
>> """if request.method =='POST':"""
>> logout(request)
>> messages.success(request,('You have been logged out'))
>> return redirect('home')
>>
>> def register_user(request):
>> if request.method =='POST':
>> form = SignUpForm(request.POST)
>> if form.is_valid():
>> form.save()
>> username = form.cleaned_data['username']
>> password = form.cleaned_data['password1']
>> user = authenticate(username=username, password=password)
>> login(request, user)
>> messages.success(request,(' Successfully Registered!'))
>> return redirect('home')
>> else:
>> form = SignUpForm()
>>
>> context = {'form': form }
>> return render(request, 'authenticate/register.html', context)
>>
>> urls.py
>>
>> from django.urls import path
>> from . import views
>> urlpatterns = [
>> path('', views.home, name="home"),
>> path('login/', views.login_user, name="login"),
>> path('logout/', views.logout_user, name='logout'),
>> path('register/', views.register_user, name='register'),
>> ]
>>
>> forms.py
>> from django.contrib.auth.forms import UserCreationForm, UserChangeForm
>> from django.contrib.auth.models import User
>> from django import forms
>>
>> class SignUpForm(UserCreationForm):
>> email = forms.EmailField()
>> first_name = forms.CharField(max_length=100,)
>> last_name = forms.CharField(max_length=100,)
>> class meta():
>> model = User
>> fields = ('username', 'first_name', 'last_name', 'email', 'password1',
>> 'password2', )
>>
>> register.html
>> {% extends 'authenticate/base.html'%}
>> {% block content%}
>> This is the Registration Page
>> 
>> {% csrf_token %}
>> {% if form.errors %}
>> Your form has errors
>> {{ error }}
>> {% endif %}
>> 
>> {{ form.as_p }}
>> 
>> 
>> 
>> 
>> {% endblock %}
>>
>>
>> Chao!
>>
>> Adrian
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
> 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 

Re: New to Django: Please Help!! Django User Model not saving first_name, last_name and email - Authentication App

2018-10-30 Thread Adrian Chipukuma
I have  sorted it out using  a different approach  'AbstractUser'. Thanks

On Tue, Oct 30, 2018, 12:19 PM Adrian Chipukuma 
wrote:

> Thanks  for the help.  Though if I  remove  the declarations of the
> first_name, last_name and email. Then  I will  not be able to see these  in
> the Register form.. The fields password1 and password2 are just working
> well and can be saved...  The issue  is on the  first_name, last_name and
> email fields...  I can't save them using  the django form..
>
> On Tue, Oct 30, 2018, 7:49 AM Manjunath  wrote:
>
>> Remove declaration of first_name, last_name & email in Form calss.
>> class SignUpForm(UserCreationForm):
>> class meta():
>> model = User
>> fields = ('username', 'first_name', 'last_name', 'email',
>> 'password1', 'password2', )
>>
>>  And while Saving the form, follow below steps.
>> if form.is_valid():
>>new_user = form.save(commit=False)
>>new_user.set_password(form.cleaned_data['password1'])
>>   new_user.save()
>>   # Your next steps
>>
>>
>> I think you might need to declare password1 & password2 fields in your
>> Form. Do Check.
>>
>>
>>
>> On Monday, October 29, 2018 at 10:04:39 PM UTC+5:30, Adrian Chipukuma
>> wrote:
>>>
>>> Hello,
>>>
>>> I am new to Django and enjoying the learning process, unfortunately I am
>>> stuck, and I need expert guidance.
>>> I am learning through developing a User Authentication System. The
>>> system is supposed to have a user registration functionality, login, user
>>> profile editing and logout. I have managed to create the login, logout
>>> functionalities and the registration functionality partly. The problem is
>>> on the registration, I am only able to save the 'username and password '
>>> using django forms, I have written the code for saving the first_name and
>>> the last _name as well as email but it seems not to be working, only the
>>> 'username and password' are saved.. I think I am missing something though
>>> no error comes up. Please anyone to guide me. Thank you.
>>> the code is as shown below:
>>>
>>>
>>> views.py
>>> from django.shortcuts import render, redirect
>>> from django.contrib.auth import authenticate, login, logout
>>> from django.contrib.auth.models import User
>>> from django.contrib import auth, messages
>>> from django.contrib.auth.forms import UserCreationForm
>>> from django import forms
>>> from .forms import SignUpForm
>>>
>>> def home(request):
>>> return render(request, 'authenticate/home.html', {})
>>>
>>> def login_user(request):
>>> if request.method == 'POST':
>>> username = request.POST['username']
>>> password = request.POST['password']
>>> user = authenticate(request, username=username, password=password)
>>> if user is not None:
>>> login(request, user)
>>> messages.success(request,('You have been logged in'))
>>> return redirect('home')
>>> else:
>>> messages.success(request,('Error Logging in!'))
>>> return redirect('login')
>>> else:
>>> return render(request, 'authenticate/login.html', {})
>>>
>>> def logout_user(request):
>>> """if request.method =='POST':"""
>>> logout(request)
>>> messages.success(request,('You have been logged out'))
>>> return redirect('home')
>>>
>>> def register_user(request):
>>> if request.method =='POST':
>>> form = SignUpForm(request.POST)
>>> if form.is_valid():
>>> form.save()
>>> username = form.cleaned_data['username']
>>> password = form.cleaned_data['password1']
>>> user = authenticate(username=username, password=password)
>>> login(request, user)
>>> messages.success(request,(' Successfully Registered!'))
>>> return redirect('home')
>>> else:
>>> form = SignUpForm()
>>>
>>> context = {'form': form }
>>> return render(request, 'authenticate/register.html', context)
>>>
>>> urls.py
>>>
>>> from django.urls import path
>>> from . import views
>>> urlpatterns = [
>>> path('', views.home, name="home"),
>>> path('login/', views.login_user, name="login"),
>>> path('logout/', views.logout_user, name='logout'),
>>> path('register/', views.register_user, name='register'),
>>> ]
>>>
>>> forms.py
>>> from django.contrib.auth.forms import UserCreationForm, UserChangeForm
>>> from django.contrib.auth.models import User
>>> from django import forms
>>>
>>> class SignUpForm(UserCreationForm):
>>> email = forms.EmailField()
>>> first_name = forms.CharField(max_length=100,)
>>> last_name = forms.CharField(max_length=100,)
>>> class meta():
>>> model = User
>>> fields = ('username', 'first_name', 'last_name', 'email', 'password1',
>>> 'password2', )
>>>
>>> register.html
>>> {% extends 'authenticate/base.html'%}
>>> {% block content%}
>>> This is the Registration Page
>>> 
>>> {% csrf_token %}
>>> {% if form.errors %}
>>> Your form has errors
>>> {{ error }}
>>> {% endif %}
>>> 
>>> {{ form.as_p }}
>>> 
>>> 
>>> 
>>> 
>>> {% endblock %}
>>>
>>>
>>> Chao!
>>>
>>> Adrian
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" gr

Re: Django user model. 1 admin account, 1 customer account with the same email and different password

2020-04-12 Thread Ernest Thuku
Option 2 seems good...I could think of it before proceeding to any other
option
On Apr 13, 2020 04:02, "Kenny Soh"  wrote:

> Im trying to handle a use case where i have 2 roles. (admin , customer)
>
> There will be an admin portal and a customer portal (2 different login
> pages ).
>
>- An admin can invite a customer
>- An admin can be a customer as well , can invite himself into the
>customer portal
>- An admin account must not share the same password as the customer
>account.
>- Email is used as the unique field for both admin and customer
>account.
>
> For example :
>
> Admin account - custo...@email.com /password1
> Customer account - custo...@email.com /password2
>
> Solution 1: - Permission. Having 1 account with admin permission and
> customer permission. (This cant work to fit the business use case)
>
> Based on this article: https://simpleisbetterthancomplex.com/
> tutorial/2018/01/18/how-to-implement-multiple-user-types-with-django.html
>
> Solution 2: - Creating 2 django projects. One for each user model since
> both accounts cant share password. The reason for separating into 2
> projects is because resources such as session,login, logout will not be
> shared. So each portal(admin,customer) has their own resource.
>
>-
>
>A create Customer API to allow admin to create a customer account in
>customer django project.
>-
>
>A shared db to share related data
>
> This is the only way i can think of to handle the use case. Please let me
> know if anyone has a better idea to handle this.
>
> --
> 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 view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/181ec499-e36c-4009-9587-06386219ab8d%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPsfuofROv_awKgFNOiM8vYe-vHLX9a9KVwPFX-9NdSHp_f3Zw%40mail.gmail.com.


Re: Django user model. 1 admin account, 1 customer account with the same email and different password

2020-04-13 Thread Carsten Fuchs
Hello,

Am 13.04.20 um 02:59 schrieb Kenny Soh:
>   * An admin account must not share the same password as the customer account.

Your entire problem would become much easier if you just dropped that 
requirement. Whatever you want to achieve with forcing a single user to keep 
two passwords, I'm sure that you're better off with a different approach.

Importantly, dropping this requirement gives you the option to follow the 
advice in the article that you linked 
(https://simpleisbetterthancomplex.com/tutorial/2018/01/18/how-to-implement-multiple-user-types-with-django.html)

Best regards,
Carsten

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bccdd94d-2344-b1c2-0478-c4e0d47d0d51%40cafu.de.


Re: Django user model. 1 admin account, 1 customer account with the same email and different password

2020-04-13 Thread Bill Freeman
Many e-mail systems allow you to add a suffix to the username portion of
the address, separated by something like a "-", or, last time I checked for
gmail, by a "+", and it will still be delivered to the same mailbox.  For
example, I expect mail sent to
 ks.kennysoh+ad...@gmail.com
will still reach you.  But username match in Django probably won't treat
these the same, so you could have two accounts: custo...@email.com, and
customer-zy...@email.com which, being separate Django accounts, could have
separate passwords.

That's not ideal because there are almost certainly some email providers
who don't follow this convention, and will treat the two addresses as
different, making it impossible to get activation emails, password reset
emails, and anything else that you want the Django instance to send you.

If you are willing to crawl down inside the Django code and make changes,
you can rework user so that, for example, username isn't unique, but
username and admin flag are "unique_together" (providing that the database
that you are using supports it), in which case these can be separate
accounts.  Or you could add decorations to the user field that are
impossible to type because your login code doesn't allow the separator,
which can be something not allowed in email addresses, like the nul
character, but you then also have to modify email sending to drop any such
decorator when producing the "to" part of a message.

But modifying the core code means re-applying the patch whenever you take
an update, and if things have changed in the area(s) that you modified,
recoding may be required, so changing the core code is considered fragile.

It might be (I'll let you investigate for yourself) that the supported
custom User model scheme lets you override user lookup at login in a
suitable way, decorating the username with, for example, a leading A for
admins and a leading U for normal users, but keep the undecorated email
address in a separate email field.  So long as whatever method you have to
override is part of the formal custom user model mechanism, it should be
pretty stable.

Good luck

On Mon, Apr 13, 2020 at 4:17 AM Carsten Fuchs  wrote:

> Hello,
>
> Am 13.04.20 um 02:59 schrieb Kenny Soh:
> >   * An admin account must not share the same password as the customer
> account.
>
> Your entire problem would become much easier if you just dropped that
> requirement. Whatever you want to achieve with forcing a single user to
> keep two passwords, I'm sure that you're better off with a different
> approach.
>
> Importantly, dropping this requirement gives you the option to follow the
> advice in the article that you linked (
> https://simpleisbetterthancomplex.com/tutorial/2018/01/18/how-to-implement-multiple-user-types-with-django.html
> )
>
> Best regards,
> Carsten
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/bccdd94d-2344-b1c2-0478-c4e0d47d0d51%40cafu.de
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB%2BAj0vMhTCCstNx87gtRunX_eoEJiZhQ_%2BZAcA_invnRrno2w%40mail.gmail.com.


django user model error: Hello friends, I keep getting this error; "accounts.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'User.groups'. Please help

2019-06-14 Thread Kenaz Odhiambo


from django.contrib.auth.models import AbstractUser
from django.core.validators import (
MinValueValidator,
MaxValueValidator,
RegexValidator
)
from django.db import models
from django.utils.translation import ugettext_lazy as _

from .managers import UserManager


class User(AbstractUser):
username = models.CharField(
_('username'), max_length=30, unique=True, null=True, blank=True,
help_text=_(
'Required. 30 characters or fewer. Letters, digits and '
'@/./+/-/_ only.'
),
validators=[
RegexValidator(
r'^[\w.@+-]+$',
_('Enter a valid username. '
'This value may contain only letters, numbers '
'and @/./+/-/_ characters.'), 'invalid'),
],
error_messages={
'unique': _("A user with that username already exists."),
})

email = models.EmailField(unique=True, null=False, blank=False)
contact_no = models.IntegerField(unique=True, blank=True, null=True)

objects = UserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []

def __str__(self):
return self.email

@property
def account_no(self):
if hasattr(self, 'account'):
return self.account.account_no
return None

@property
def full_name(self):
return '{} {}'.format(self.first_name, self.last_name)

@property
def balance(self):
if hasattr(self, 'account'):
return self.account.balance
return None

@property
def full_address(self):
if hasattr(self, 'address'):
return '{}, {}-{}, {}'.format(
self.address.street_address,
self.address.city,
self.address.postal_code,
self.address.country,
)
return None


class AccountDetails(models.Model):
GENDER_CHOICE = (
("M", "Male"),
("F", "Female"),
)
user = models.OneToOneField(
User,
related_name='account',
on_delete=models.CASCADE,
)
account_no = models.PositiveIntegerField(
unique=True,
validators=[
MinValueValidator(1000),
MaxValueValidator()
]
)
gender = models.CharField(max_length=1, choices=GENDER_CHOICE)
birth_date = models.DateField(null=True, blank=True)
balance = models.DecimalField(
default=0,
max_digits=12,
decimal_places=2
)
picture = models.ImageField(
null=True,
blank=True,
upload_to='account_pictures/',
)

def __str__(self):
return str(self.account_no)


class UserAddress(models.Model):
user = models.OneToOneField(
User,
related_name='address',
on_delete=models.CASCADE,
)
street_address = models.CharField(max_length=512)
city = models.CharField(max_length=256)
postal_code = models.PositiveSmallIntegerField()
country = models.CharField(max_length=256)

def __str__(self):
return self.user.email

-- 
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/2a43175d-5279-401a-a97d-6b1036f1ca52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.