Week 6: Creating An Efficient System
April 12, 2023
SP Week 6 Post Hey everyone! So last week, I mentioned that I’d completely reorganize the database structure and create a new set(s) of models (tables in the database). There are two new models I’d like to create and restructure: Users and the existing Ingredients. Let’s start with the Users:
Originally, I was using Django’s built in user registration system. This allowed me to directly import a UserCreationForm from Django’s library, which allowed us to create a new user with the following information: username and password. However, I realized that this information wasn’t enough, and I needed to gain more information about the users for future transactions and donations.
First I created an organization field, which allows users to specify which organization they are representing. For instance, if Sam is the name of a manager at Willow Glen Soup Kitchen, he would be able to specify Willow Glen Soup Kitchen while signing in. This would allow multiple users to represent a single soup kitchen, and the organization name would be visible during transactions for clarity.
organizationName = models.CharField(max_length=100, null=True)
I also created a zip code field, which allows users to see each other’s general location so donations can be made efficiently. This would allow users within close proximity to see each other’s donations, while avoiding impossible donations from very far away.
zipCode = models.IntegerField(null=True)
The next new field is an email, which allows users to enter their work email address so I can communicate with the users and users can communicate with each other. I also added a last_login variable, which records the last login time and an isAdmin field to keep track of users with special privileges (for future):
email = models.EmailField(max_length=100, unique=True)
last_login = models.DateTimeField(auto_now=True)
is_admin = models.BooleanField(default=False)
But most importantly, I created a user ID, which helps me keep track of individual users. This user ID will one used to connect users to ingredients:
id = models.AutoField(primary_key=True)
Regarding the Ingredients, I first found a database with individual ingredient IDs. For instance, bananas can be identifies to ‘ ‘ while apples are ‘ ‘. This is the systems soup kitchens use to organize their incoming donations, and implementing a similar system would make it easier for the soup kitchens. Additionally, this would help prevent errors created by typos and help different different types of ingredients (example: wild rice from brown rice).
I also created a pending variable in the Ingredient model, which would help me keep tracked of finished donations. The pending variable is initially false, and once a donation is made it becomes true. Once it becomes true, the donations will be added to an ArrayList of Ingredient objects, which store all transactions for tax benefit purposes. Although the ArrayList is only ingredient objects, any ingredient can be tracked back to its user through the ID system.
That’s all for this week, I’ll catch you guys in the next post!