Username same as user id

21 views
Skip to first unread message

lakshitha kumara

unread,
May 6, 2018, 2:43:55 PM5/6/18
to Django users
Hello guys 

Is there way to assign username same as user id if username passing empty value on registration form. is there way to do that.

Thanks

lakshitha kumara

unread,
May 6, 2018, 4:48:02 PM5/6/18
to Django users
hi anthony 

Thank you for reply on this site username field not required field for user  but its set as required field on backend so i need assing user id as as username if username is empty for on registration submit. 
user can login with email phone and username 

Thanks 

Anthony Flury

unread,
May 6, 2018, 5:27:52 PM5/6/18
to django...@googlegroups.com
I can't imagine having an application where username is optional ...
> --
> 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
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto: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/ed1f8b3c-301e-400c-b493-a55f49f2cdc5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ed1f8b3c-301e-400c-b493-a55f49f2cdc5%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
--
Anthony Flury
email : *Anthon...@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

lakshitha kumara

unread,
May 7, 2018, 12:57:00 AM5/7/18
to Django users
hi anthony 

Look at the facebook registration form. there are no username field first time user registration. but once user registered they can set username what they want. 

Thanks 

On Sunday, May 6, 2018 at 8:13:55 PM UTC+5:30, lakshitha kumara wrote:

Jani Tiainen

unread,
May 7, 2018, 6:18:24 AM5/7/18
to django...@googlegroups.com
Hi,

Have you considered using custom user with custom authentication backend to handle authentication?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

lakshitha kumara

unread,
May 7, 2018, 6:22:13 AM5/7/18
to Django users

Hello Jeni 

Thank you for your reply. yes i dealing with my own custom authentication backend and now i desided to use username as random number Instead of user id if username not set.

Thanks you

On Sunday, May 6, 2018 at 8:13:55 PM UTC+5:30, lakshitha kumara wrote:

Anthony Flury

unread,
May 7, 2018, 8:06:07 AM5/7/18
to django...@googlegroups.com
Of course there is :
on the view which responds to your registration form (likely to be where
you call authenticate) - you simply test if the username field has been
set when the registration is posted - and if not set it to be whatever
you want.

Or - in your custom backend you can do the same thing; basically you
have code like this :

if not username:
    username = random_digits()

where random_digits is a function you write to generate your random user
name/number.

Remember you will need to tell the user what number you have chosen for
them.

This isn't really a Django issue to be honest - it is simply code.
> --
> 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
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto: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/a5474895-5676-449f-834f-4d3ab30594dd%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a5474895-5676-449f-834f-4d3ab30594dd%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Anthony Flury

unread,
May 7, 2018, 8:09:01 AM5/7/18
to django...@googlegroups.com
Yes - but that is very different from what you are asking - Facebook
have a two stage form - first set the details - and then set the user
name. Their user name isn't optional - it is always mandatory - it is
just set at stage two.

You can assign any value to any variable you wish - this isn't a Django
issue.
> --
> 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
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto: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/e7eb07c0-6162-4c88-b5b4-8d1a5ee2d4b6%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/e7eb07c0-6162-4c88-b5b4-8d1a5ee2d4b6%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages