Monday, February 14, 2022

Re: How to validate xl data


Sujata Aghor <sujatas4aghor@gmail.com> schrieb am Di., 15. Feb. 2022, 06:24:
Hi Prashant,
If you are talking about server side validations, then you can do that for each row/ cell values before inserting data into db.

Regards!

On Mon, Feb 14, 2022 at 12:05 PM Prashanth Patelc <prashanthpatelc@gmail.com> wrote:
i am working on xl sheets , when im uploading the xl sheet it is storing into the models but i need before storing into the models validate the data

eg:
username : ,must be str not int
reference id : ,must be int not str
email : ,contains @gmail.com , not strt not int

i need to validate like above


this is code my code 
working but i need validations


class UploadPersonView(APIView): permission_classes = [IsAuthenticated, IsAdminPermission | IsSuperAdminPermission]
serializer_class = PersonUploadSerializer
def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
dataset = Dataset()
file = serializer.validated_data['file']
imported_data = dataset.load(file.read(), format='xlsx')
'''uploading xl file with particular data what user mentioned in xl we are looping the xl data
and appending into the database with same fields''' # validate data here before upload
for data in imported_data:
person_data = UserProfile(username=d,
fullname=data[1],
mobile=d2,
email=data[3],
password=make_password(data[4]),
date_joined=data[5],
is_verified=data[6],
is_active=data[7],
is_admin=data[8],
is_manager=data[9],
is_tl=data[10],
is_agent=data[11],
orginization=data[12],
dob=data[13],
gender=data[14],
team_name_id=data[15],
role=data[16]
)
person_data.save()
return Response({'sucessfully uploaded your file'}, status=status.HTTP_200_OK)
except:
return Response({'message': 'aaa'}, status=status.HTTP_404_NOT_FOUND)

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


--

Thanks & Regards!
Sujata S. Aghor

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJCP8KC%3DkNehcD9ixe6VjxFVSvxe9rrFTMm3A941%2Btv9Ppe%3Dgg%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKGT9mw3jvVivmd4GFEg7BU9_Grxg24ACdQYEUbdQwUSPHzCRg%40mail.gmail.com.

No comments:

Post a Comment