The Intricacies of Database Design

Ritwick Raj
AnitaB.org Open Source
2 min readJul 21, 2020

Previously, in one of my blogs, I had mentioned about the difficulties one has to face while working on an existing project. One has to go through the code and understand the ways in which different transactions and implementations are designed.

Understanding the methods becomes a crucial part of the work. So this became the case again while jumping onto the Phase 2 issues for GSoC.

So after completing the meetup history feature for the Portal, I jumped onto adding subscription settings for users, which would allow them to choose whether to receive weekly digests and reminders.

Discovering Methods

First one was to simply add the fields to the User Model, and then create a different form altogether to just edit the settings. This created certain problems.

  • The SystersUser Model of the Portal does not inherit from the AbstractUser Model. Rather it has a one to one field with the user object. This caused lots of issues, as there were two user models.
  • The forms for Editing User Profile was derived from the other user model in a very complicated manner which was making it difficult to just add the form with specific fields
  • Making Changes to the Pre-existing Models would make tests to fail and which would consume a lot more time, rather than just adding extra tests for the new model.

Then we were left with the second way to implement this., which was creating a model for the settings and then linking it to the user model as a one to one field.

class UserSetting(models.Model):
user = models.OneToOneField(SystersUser, on_delete=models.CASCADE)
weekly_digest = models.BooleanField(default=False)
location_change = models.BooleanField(default=False)
time_change = models.BooleanField(default=False)
reminder = models.BooleanField(default=False)

def __str__(self):
return "Settings for {0}".format(self.user)

Then I went on the create the forms to edit and change the model.

Stay tuned for the next blog for further updates on the workflow of the feature

--

--