Search code examples
djangoumlclass-diagrammodel-associationsmultiplicity

UML association class and OOP languages


I am building a web application with Django, I did the design app with UML2. i read that association class concept does not exist in object oriented programming languages, is that true ?? thank you.

class diagram

class diagram


Solution

  • No. You can implement that model relationship design as follows:

    class Society(models.Model):
        name = models.CharField(max_length=100)
    
    class User(models.Model):
        name = models.CharField(max_length=100)
        societies = models.ManyToManyField(Society, through='Employment', related_name='users', blank=True)
    
    class Employment(models.Model):
        class Meta:
            unique_together = [('user', 'society')]
        user = models.ForeignKey(User, on_delete=models.CASCADE)
        society = models.ForeignKey(Society, on_delete=models.CASCADE)
        salary = models.IntegerField()