forked from alexaorrico/AirBnB_clone_v2
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80a5abf
commit 3512319
Showing
5 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/python3 | ||
""" | ||
Contains class BaseModel | ||
""" | ||
|
||
from datetime import datetime | ||
import uuid | ||
|
||
|
||
class BaseModel: | ||
"""The BaseModel class from which future classes will be derived""" | ||
def __init__(self): | ||
"""Initialization of the base model""" | ||
self.id = str(uuid.uuid4()) | ||
self.created_at = datetime.now() | ||
self.updated_at = self.created_at | ||
|
||
def __str__(self): | ||
"""String representation of the BaseModel class""" | ||
return "[{:s}] ({:s}) {}".format(self.__class__.__name__, self.id, | ||
self.__dict__) | ||
|
||
def save(self): | ||
"""updates the attribute 'updated_at' with the current datetime""" | ||
self.updated_at = datetime.now() | ||
|
||
def to_dict(self): | ||
"""returns a dictionary containing all keys/values of the instance""" | ||
time = "%Y-%m-%dT%H:%M:%S.%f" | ||
new_dict = self.__dict__.copy() | ||
new_dict["created_at"] = new_dict["created_at"].strftime(time) | ||
new_dict["updated_at"] = new_dict["updated_at"].strftime(time) | ||
new_dict["__class__"] = self.__class__.__name__ | ||
return new_dict |
Empty file.
Empty file.
Empty file.