Skip to content

forum app | Doubled tables with the same purpose #20

@LiorA1

Description

@LiorA1

In the forums app, if we take a look at the models.py module, one can see there two models: Forum and Comment.
In the Forum model defined 'comments' ManyToMany field. And in the Comment a 'forum' ForeignKey field.

According to Django Docs, a ForeignKey to a model (in our case: Forum) auto-generates the reverse-access-manager (with the name: _set ).
Docs: https://docs.djangoproject.com/en/3.2/topics/db/queries/#following-relationships-backward
(It exists also in the m2m field)

Its actually a table that Django generates for us. In our case: 'comment_set'.
We can see that exist two tables with the same purpose ('comment_set' and 'comment'), so we basically create a situation with redundant table.

Image here: https://github.com/LiorA1/Django/blob/main/dj4e-samples/forums/DJ4ESpecialization.png
Fix Suggestion here: https://github.com/LiorA1/Django/blob/main/dj4e-samples/forums/models.py

Thanks

P.S: The same issue exists in the favs App.
P.S 2: For Non C.S Grads, it maybe be beneficial to see it explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions