Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Portfolio Models to Simulateur Platform #81

Open
antoinebou12 opened this issue Jul 3, 2024 · 0 comments
Open

Add Portfolio Models to Simulateur Platform #81

antoinebou12 opened this issue Jul 3, 2024 · 0 comments
Assignees

Comments

@antoinebou12
Copy link
Member

Overview

This ticket is to add and integrate the Portfolio models into the Simulateur stock market simulation platform using Django's ORM. The Portfolio models manage the relationships between users, teams, stocks, and transaction histories within the simulation. The objective is to ensure that portfolios are correctly modeled and integrated into the existing system.

Steps to Implement Portfolio Models

  1. Add Portfolio Models:

    • Create or update the portfolio.py file in the simulation/models directory with the provided code.

      from django.db import models
      
      class Portfolio(models.Model):
          owner = models.OneToOneField('UserProfile', on_delete=models.CASCADE, null=True, blank=True, related_name='portfolio')
          teams = models.ManyToManyField('Team', related_name='portfolios', blank=True)
          balance = models.DecimalField(max_digits=10, decimal_places=2, default=0.00)
          stocks = models.ManyToManyField('Stock', through='StockPortfolio')
          transactions = models.ManyToManyField('TransactionHistory', related_name='portfolios', blank=True)
      
          def __str__(self):
              return f'Portfolio for {self.owner or self.team}'
      
          class Meta:
              verbose_name_plural = "Portfolios"
      
      class StockPortfolio(models.Model):
          stock = models.ForeignKey('Stock', on_delete=models.CASCADE)
          portfolio = models.ForeignKey('Portfolio', on_delete=models.CASCADE)
          quantity = models.IntegerField(default=0)
      
          class Meta:
              unique_together = ('stock', 'portfolio')
  2. Update Existing Models:

    • Ensure that related models such as UserProfile, Team, Stock, and TransactionHistory are correctly defined and import the necessary relations from portfolio.py.

      For example, update UserProfile and Team models if they are not already updated:

      from django.db import models
      
      class UserProfile(models.Model):
          balance = models.FloatField()
          user = models.OneToOneField(User, on_delete=models.CASCADE)
          team = models.ForeignKey('Team', on_delete=models.CASCADE)
      
      class Team(models.Model):
          name = models.CharField(max_length=100)
          members = models.ManyToManyField(UserProfile)
  3. Create Migrations:

    • Generate and apply the database migrations to reflect the new and updated models.
      python manage.py makemigrations
      python manage.py migrate
  4. Update Admin Interface:

    • Register the new models in the admin interface if needed by updating admin.py:
      from django.contrib import admin
      from .models import Portfolio, StockPortfolio
      
      admin.site.register(Portfolio)
      admin.site.register(StockPortfolio)
  5. Test the Integration:

    • Start the Django server and verify that the portfolio models are correctly integrated and functional. Test creating, updating, and retrieving portfolio instances via the admin interface or through the Django shell.

Expected Behavior

The platform should be able to manage user and team portfolios, including the associated stocks and transaction histories. Users should be able to view and manage their portfolios through the appropriate interfaces.

Additional Information

Ensure that the portfolio balance is accurately updated based on transactions and stock holdings. The relationships and constraints defined in the models should be validated to prevent data inconsistencies.

@antoinebou12 antoinebou12 self-assigned this Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant