0

Usecase

The app that I am developing is about linking startup, job seekers and investors. Sorry I could not give the name still though I have developed already around 40% :) .There will be three entities. One is Startup account, Enduser account and Investor account. I am thinking of adding follow/unfollow feature where

  • Enduser can follow Startup and vice-versa
  • Startup can follow Investor and vice-versa
  • Enduser cannot follow other enduser and enduser cannot follow investor

For this how should I model my application

Here is the model for the entities I talked about

Enduser Model

class UserSetting(models.Model):
    user = models.OneToOneField(User)
    job_interest = models.ManyToManyField(Category, related_name='user')
    is_email_notification = models.BooleanField(
        default=True, help_text="Email me job recommendations based on my interests and preferences")

    class Meta:
        verbose_name = 'User Setting'
        verbose_name_plural = 'User Settings'

    def __str__(self):
        return self.user.username

Startup Model

class Startup(models.Model):
    name = models.CharField(max_length=200, unique=True,
                            blank=False, null=False)
    slug = models.SlugField(unique=True)
    description = models.CharField(max_length=400)

Investor Model

class Investor(models.Model):
    investor = models.ForeignKey(User, on_delete=models.CASCADE)
    name = models.CharField(max_length=200, blank=False,
                            null=False, help_text='Full Name')
    slug = models.SlugField(max_length=200, unique=True)
    contact_email = models.EmailField(null=True, blank=True)
    # for now I have done like this
    followers = models.ManyToManyField(
        User, related_name='followers', blank=True)

For now, you can see I have included the followers field in the Investor but I need the follower system in the startup as well so that enduser can follow startup and vice-versa. Also in following investor only startup can follow but enduser should not.

What is the best possible solution for this?

milan
  • 2,409
  • 2
  • 34
  • 71

1 Answers1

0

It sounds like you are looking to build junction objects. You want to register Users against those objects. So I would probably redesign your data model a little. Here are my thoughts:

  • Investors are a group of users under a name (Pasadena Angels, XYZ Venture Partners, etc)
  • Startup is a company with a group of users
  • End-User is a singular User

But django authenticated Users can be "Investors", "Startup Employees", or "End Users". AND it is more than likely that Angel Investors are Executive Employees at a Startup. And it's possible, actually it sounds desireable that over time an EndUser becomes a Startup Employee.

Therefore I'd do something like this:

class EndUser(models.Model):
    user = models.OneToOneField(User)
    ...

class Startup(models.Model):
    name = models.CharField(max_length=100)
    ...

class StartupEmployee(models.Model):
    user = models.ForeignKey(User)
    startup = models.ForeignKey(Startup)
    ...

class InvestmentFirm(models.Model):
    name = models.CharField(max_length=100)
    ...

class Investor(models.Model):
    user = models.ForeignKey(User)
    firm = models.ForeignKey(InvestmentFirm)
    ...

class Follower(models.Model):
    user = models.ForeignKey(User)
    startup = models.ForeignKey(Startup, blank=True, null=True)
    firm = models.ForeignKey(InvestmentFirm, blank=True, null=True)
    ...

My thought process is that the data model does not need to control the logic of who can follow who. My thought process is that the application will have separate views which can control who can see what. In other words the data model shouldn't prevent end-users from following other end-users. That should be part of the UI/UX.

Thats my quick hack at a recommendation.

sahutchi
  • 2,223
  • 2
  • 19
  • 20
  • Will you recommend to create a Follower a new app? – milan Oct 10 '17 at 06:08
  • This is a different topic, but I would not create an app per UserGroup. I try to keep as much of the data model in the same app. I normally create a core app which houses as much of the data model as practical because as you point out, some objects should be shared. – sahutchi Oct 10 '17 at 06:12
  • I did not understand one thing. why you have used the InvestmentFirm to follow instead of using Invester? – milan Oct 10 '17 at 09:41
  • Investor is one-to-one with User whereas InvestorFirm gives you the ability to aggregate organizations. I'm not sure if you are looking to sell this product, but setting it up this way may prevent you from doing a full refactor to support enterprise style roles and permissions. – sahutchi Oct 10 '17 at 15:57