#M05 Creating Hackathon Database Models#72
#M05 Creating Hackathon Database Models#72stefdworschak merged 32 commits intoCode-Institute-Community:masterfrom
Conversation
Created hackathon app and moved tests inside its own module.
Updating branch with base files.
Connected the "hackathon" app by urls and settings"
Foregin Key fields will be revised as other models are created.
Added to admin. Minor adjustment made to Hackathon related name field
Updated comments. Must update all FK fields.
Foreign Keys match the schema closely but need review. See comments.
Syncing with changes from upstream repo
Sitched the *-Link fields for URLFields. Added comments.
Sitched the *-Link fields for URLFields. Added comments. Added URLFields to project Model Changed *_link to URLField, added comments. This commit fixes issue #61
…to m05 Updating commits to append request to issue.
Should not be commited here.
stefdworschak
left a comment
There was a problem hiding this comment.
Overall a really good Pull Request. Some suggestions on how to proceed and let me know if you have any questions.
| created_by = models.ForeignKey(User, | ||
| on_delete=models.CASCADE, | ||
| related_name="hackathon_created_by") | ||
| display_name = models.CharField(default="", max_length=254) |
There was a problem hiding this comment.
I would allow blank and null instead of defaulting to an empty string. I think that's a little bit cleaner.
There was a problem hiding this comment.
I used this because the docs recommend to not do that for string-based fields here.
https://docs.djangoproject.com/en/3.1/ref/models/fields/#null
Let me know if you want me to swap it out anyway, and I'll do that. I've marked the other convos with this resolved for now tell me what you think here and I'll apply it to all of them.
There was a problem hiding this comment.
Okay, just learnt something new. Did not know that, but let's follow the Django documentation then.
There was a problem hiding this comment.
Actually, I was doing the same thing myself until recently, then I found this. It only has a few rules, but it's useful:
https://github.com/rocioar/flake8-django
There was a problem hiding this comment.
That's really useful! Thanks for sharing.
There was a problem hiding this comment.
I implemented the requested changes. Main points:
- I'm using
default=""because Django docs recommend it for string fields. If you prefer, I'll change it. - I removed the quotes around "Hackathon" but left them for "HackProject", take a look at the comment.
- I think I made that last change for the model correctly, but let me know if it's right!
- Tests are incoming!
I'm also wondering should I remove the comments over FK fields before a full pull?
Thank you for all the effort ye put into supporting the project, it's a great experience for me. :-)
| created_by = models.ForeignKey(User, | ||
| on_delete=models.CASCADE, | ||
| related_name="hackathon_created_by") | ||
| display_name = models.CharField(default="", max_length=254) |
There was a problem hiding this comment.
I used this because the docs recommend to not do that for string-based fields here.
https://docs.djangoproject.com/en/3.1/ref/models/fields/#null
Let me know if you want me to swap it out anyway, and I'll do that. I've marked the other convos with this resolved for now tell me what you think here and I'll apply it to all of them.
…to m05 Consolidating an amend.
Also Changed model field name for readability.
hackathon/models.py
Outdated
| # Each model can only be created by one user: One To Many | ||
| created_by = models.ForeignKey(User, | ||
| on_delete=models.CASCADE, | ||
| related_name="hackathon_created_by") |
There was a problem hiding this comment.
Sorry, I should have mentioned this in the other comment, but I would just rename all the related_names for created_by to be just the plural of the model name in lower case. I think that would be the best seeing as it they are basically a collection of that model created by a user.
There was a problem hiding this comment.
Okay, makes sense, I'll do that now.
|
Also, don't forget to fix the merge conflict. |
|
Okay, I changed the related names to plurals, I merged the conflict in the .gitignore adding both lines. And there are some basic str method tests in there too now. I think it should be good to go. If you have any other corrections, let me know and I'll get right to it! :-) |
…to m05 Merging with latest updates
stefdworschak
left a comment
There was a problem hiding this comment.
LGTM
Really good pull request! 👍
These models are a draft that will fix issue #61
TLDR at the end.
Overview
The models.py file contains the models built from the schema here on the Development Wiki. I have followed the schema to the best of my ability. I definitely need other contributors to take a look at the fields for the Foreign Keys because I did change some of them.
I have given my reasoning for the choices in comments above each Foreign Key field. If anybody can see any errors or has a better idea of how to relate them, the advice is well appreciated! :-)
Testing
I have created each model in my own environment, it all seems grand. I deleted the DB and remigrated everything, I haven't had any errors yet. Models have a testing file that checks they can be created correctly and their
strmethod.To Do
Displaying info from the related tables and making it editable on a different model's page would make this way easier! However, I think it could be started as a new issue. The models are needed to start work on other issues and it is a job in itself.
Possible Bugs
I know it is a long read, so thank you again for any help!
TLDR:
Please take a look at the Foreign Key fields and their comments and let me know if you see any issues. I'll fix them up and make the commits. ;-)