4/9/2023 0 Comments Registrasi magic lines![]() ![]() You can continue to change its # attributes if you want to change other fields. Or we can user create_user method def create(self, validated_data): user = _user(validated_data, validated_data, validated_data) # At this point, user is a User object that has already been # saved to the database. def create(self, validated_data): user = ( username=validated_data, email=validated_data, first_name=validated_data, last_name=validated_data ) t_password(validated_data) user.save() return user ![]() ![]() When send POST request to register endpoint, it calls RegisterSerializer’s create method which saves user object. We set first_name and last_name required. We can add extra validations with extra_kwargs option. fields = ('username', 'password', 'password2', 'email', 'first_name', 'last_name') These are the fields that our registration form is contains. the type of password2 attribute is an CharField and that it is write only, and required.the type of password attribute is an CharField and that it is write only, required and should be a valid password.the type of email attribute is an EmailField and that it is required and should be unique amongst all User objects in our database.email = serializers.EmailField( required=True, validators= ) password = serializers.CharField(write_only=True, required=True, validators=) password2 = serializers.CharField(write_only=True, required=True) We can create new atributes for changing model validations. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |