from werkzeug.security import generate_password_hash

class User(object):
    """Represents a user who can Create, Read, Update & Delete his own bucketlists"""

    user_id = 0
    users = {}
    user_bucketlists = {}

    def __init__(self, email, username, password):
        """Constructor to initialize class"""

        User.user_id += 1    # This line is a game changer
        self.email = email
        self.username = username
        self.password = generate_password_hash(password)


    def create_user(self):
        """ Class to create and store a user object """

        self.users.update({
            self.user_id: {
                'email': self.email,
                'username': self.username,
                'password': self.password
            }
        })

        return self.users


class Bucketlist(object):
    """Represents a class to Create, Read, Update & Delete a bucketlist"""

    buck_id = 0
    bucketlists = {}
    bucketlist_items = {}

    def __init__(self, name, description):
        """Constructor to initialize class"""

        Bucketlist.buck_id += 1    # Alter the outside class var buck_id, NB: self.buck_id works but replaces items instead of updating the dict
        self.name = name
        self.description = description


    def create_bucketlist(self):
        """ Class to create and store a bucketlist object """

        self.bucketlists.update({
            self.buck_id: {'user_id': User.user_id, 'name': self.name, 'description': self.description}
        })

        return self.bucketlists
        

    def insert_into_user(self):
        """ Give the created bucketlist to its owner """
        # User.user_bucketlists.update({
        #     User.user_id: self.bucketlists
        # })

        User.user_bucketlists[User.user_id] = self.bucketlists

        return User.user_bucketlists


class BucketlistItem(object):
    """Represents a class to Create, Read, Update & Delete bucketlist items"""

    item_id = 0
    bucketlist_items = {}

    def __init__(self, title, description, status):
        """Constructor to initialize class"""

        BucketlistItem.item_id += 1
        self.title = title
        self.description = description
        self.status = status


    def create_bucketlist_item(self):
        """ Class to create and store a bucketlist item """

        self.bucketlist_items.update({
            BucketlistItem.item_id: {
                'title': self.title,
                'description': self.description,
                'status': self.status
            }
        })
        
        return self

    def insert_into_bucketlist(self):
        """ Give the created bucketlist item to its bucketlist """
        Bucketlist.bucketlist_items.update({
            Bucketlist.buck_id: BucketlistItem.bucketlist_items
        })

@@ -188,34 +188,8 @@
 = %7B%7D
-%0A    user_bucketlists = %7B%7D
 %0A%0A  
@@ -920,34 +920,8 @@
 = %7B%7D
-%0A    bucketlist_items = %7B%7D
 %0A%0A  
@@ -1519,24 +1519,22 @@
 def 
-insert_into_user
+add_bucketlist
 (sel
@@ -1545,39 +1545,26 @@
         %22%22%22 
-Give the create
+Ad
 d bucketlist
@@ -1571,95 +1571,140 @@
  to 
-its owner %22%22%22%0A        # User.user_bucketlists.update(%7B%0A        #     User.user_id: self
+a list with an existing bucketlist %22%22%22%0A        # First get the user id from existing bucketlist%0A        bucketlist_dict = Bucketlist
 .buc
@@ -1703,32 +1703,40 @@
 list.bucketlists
+.items()
 %0A        # %7D)%0A%0A 
@@ -1732,76 +1732,230 @@
     
-# %7D)%0A%0A        User.user_bucketlists%5BUser.user_id%5D = self.bucketlists
+for k, v in bucketlist_dict:%0A            existing_owner = v%5B'user_id'%5D%0A%0A        self.bucketlists.update(%7B%0A            self.buck_id: %7B'user_id': existing_owner, 'name': self.name, 'description': self.description%7D%0A        %7D)
 %0A%0A  
@@ -1967,26 +1967,21 @@
  return 
-U
 se
-r.user_
+lf.
 bucketli
@@ -1984,16 +1984,25 @@
 etlists%0A
+        %0A
 %0A%0Aclass 
@@ -2379,17 +2379,16 @@
 status%0A%0A
-%0A
     def 
@@ -2533,33 +2533,76 @@
     
-BucketlistItem.item_id: %7B
+self.item_id: %7B%0A                'bucketlist_id': Bucketlist.buck_id,
 %0A   
@@ -2779,231 +2779,22 @@
 self
-%0A%0A    def insert_into_bucketlist(self):%0A        %22%22%22 Give the created bucketlist item to its bucketlist %22%22%22%0A        Bucketlist.bucketlist_items.update(%7B%0A            Bucketlist.buck_id: BucketlistItem.bucketlist_items%0A        %7D)
+.bucketlist_items
 %0A

Update method to create bucketlist items