Re: Django Validation error

11 views
Skip to first unread message

Wesley Montcho

unread,
Jan 9, 2020, 8:38:21 AM1/9/20
to django...@googlegroups.com
Hello 
Thanks for helping me 
I want to ask you something else, Should I create serializer.py  or it is some file I can modify

Le jeu. 9 janv. 2020 à 13:59, Suraj Thapa FC <surajt...@gmail.com> a écrit :
Use try catch and send  whatever response you want to send

On Wed, 8 Jan 2020, 10:36 pm Soumen Khatua, <soumenk...@gmail.com> wrote:

seriazlizers.py

    email = serializers.EmailField(required=True,validators=[UniqueValidator(queryset=User.objects.all())])
    phone_number = serializers.CharField(required = True,validators=[UniqueValidator(queryset=User.objects.all())])
    password = serializers.CharField(write_only=True,required=True,
                                        help_text='Leave empty if no change needed',
                                        style={'input_type': 'password', 'placeholder': 'Password'}
                                    ) 

models.py
    email = models.EmailField(_('email address'), unique=True)
    phone_number = models.CharField(max_length=10,unique = True,
                                    blank=False,default = uuid.uuid4().hex[:8])
    first_name = models.CharField(_('first name'), max_length=30)
    last_name = models.CharField(_('last name'), max_length=30, blank=True)
    is_active = models.BooleanField(_('active'), default=True)
    is_staff = models.BooleanField(_('staff status'),default=False)
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)


  I already did that but I want to raise validation error that email should be unique and password should be alphanumeric character in json format?

On Wed, Jan 8, 2020 at 9:44 PM Suraj Thapa FC <surajt...@gmail.com> wrote:
For email you can set email field in model as unique=True and the password should be  stored in hash.. 

On Wed, 8 Jan 2020, 9:37 pm Soumen Khatua, <soumenk...@gmail.com> wrote:
Hi Folk,

What is the process to validate fields in django rest framework?
like email and phone number should be unique and password should be alphanumeric character only.

Where i need to write the logic inside serializers or views part and how i can do that?

Thank you in advance

Regards,
Soumen


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6Wb7_45-r165wg10M-w%2B6V6zOheCnEC3_chbJ-GEHRGQLA%40mail.gmail.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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPjsHcFKnaczwY-%3DKWqbPWrUuecv6YYWR19qPwSWmZpSYG%2BW0w%40mail.gmail.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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WbDFeAtOxksdOijTOidX%3DW8gzCs38fN_nXMSK%3DLFxA1cg%40mail.gmail.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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPjsHcHcs2ogHe6bHJt44_0saVPsR1fgug0RrQ%3D%3DEQYJRJzwHQ%40mail.gmail.com.

Soumen Khatua

unread,
Jan 9, 2020, 11:05:06 AM1/9/20
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages