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

forum app | Doubled tables with the same purpose #20

Open
LiorA1 opened this issue Apr 20, 2021 · 1 comment
Open

forum app | Doubled tables with the same purpose #20

LiorA1 opened this issue Apr 20, 2021 · 1 comment

Comments

@LiorA1
Copy link

LiorA1 commented Apr 20, 2021

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.

@LiorA1 LiorA1 changed the title Doubled tables with the same purpose In the forum app forum app | Doubled tables with the same purpose Apr 20, 2021
@csev
Copy link
Owner

csev commented Apr 20, 2021

This is a great comment. I agree with your "P.S." statements. Let me figure out where to use this approach - I think that since it is the "Django way" - it would be good to slowly switch to this pattern.

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

2 participants