|
420 | 420 | ### Goals
|
421 | 421 | - Add a dedicated ```comments``` app and link it to ```articles```
|
422 | 422 |
|
423 |
| -### Steps |
| 423 | +### Get an model! (i.e. **comment**) |
424 | 424 | - basis
|
425 | 425 | - what to add
|
426 | 426 | - FILE: articles/**models.py**
|
427 | 427 | - CLASS: ```Comment(models.Model)``` (newly added)
|
428 | 428 | - and
|
429 | 429 | - ```./manage.py makemigrations articles```
|
430 | 430 | - ```./manage.py migrate```
|
431 |
| - |
| 431 | + - lastly |
| 432 | + - articles/**admin.py** |
| 433 | + 1. ```from .models import Article, Comment``` |
| 434 | + 2. ```admin.site.register(Comment)``` |
| 435 | + - only by doing this then the app will visible (displaying on website (?front/back)) |
| 436 | + |
| 437 | +### Now we have it at the **backend**! But it could be better |
| 438 | +- What to solve (quote from author) |
| 439 | + > ... "wouldn't it be better to just see all ```Comment``` models related to a single ```Post``` model?" ... |
| 440 | +- What to solve |
| 441 | + 1. The ```articles``` & ```comments``` app both needed to open seperately, which is **NOT** makes sense (right? 😅) |
| 442 | + 2. So, let's put it in the jar! (Nope) ***put the ```articles``` & ```comments``` on the same screen***! |
| 443 | +- How to solve |
| 444 | + - Fact |
| 445 | + - Django provides two main *inline views*: ```TabularInline```, ```StackedInline``` (tiny differences btw) |
| 446 | + - Code |
| 447 | + - modify the **admin.py** |
| 448 | +- What will be changed |
| 449 | + - Only the **admin.py** |
| 450 | +- Here we go (solutions)! |
| 451 | + - well, not clearly sayin, it's *wrapping* & *superclass* stuff :P |
| 452 | + - summary (no detailed code, I didn't fully understand it yet) |
| 453 | + 1. two new classes added |
| 454 | + 2. one more to register (to admin) |
0 commit comments