I have a list which has some dictionaries to be bulk uploaded. I need to check if elements of list can be cast to a custom object(as below). Is there any elegant way to do it like type comparison?
This is my model
class CheckModel(object):
def __init__(self,SerialNumber,UID, Guid = None,Date = None):
self.SerialNumber = SerialNumber
self.UID = UID
self.Guid = str(uuid.uuid4()) if Guid is None else Guid
self.Date = datetime.now().isoformat() if Date is None else Date
And this is my test data. How can I cast only first element(because first element is the only correct one.) of this list into CheckModel object?
test = [{
"Guid":"d0c035a7-0e01-4a37-8fe9-251fb5633fc9",
"SerialNumber":"1716154A",
"UID":"F13BDB3B",
"Date":"2019-12-03T13:50:19.882Z"
},
{
"Guid":"d0585-0e01-4a47-8fe9-251245f33fc9",
"SerialNumber":"1716154A",
"Date":"2019-12-03T13:50:19.882Z"
},
{
"Guid":"12414a7-0e01-4a47-8fe9-251245f33fc9",
"SerialNumber":"1716154A",
"UID":"F13BDB3B",
"Date":"2019-12-03"
}]