Changeset View
Changeset View
Standalone View
Standalone View
blog/models.py
| import datetime | import datetime | ||||
| from typing import Optional, Union, Sequence, Any | from typing import Any | ||||
| from django.contrib.auth.models import User | from django.contrib.auth.models import User | ||||
| from django.db import models | from django.db import models | ||||
| from django.urls import reverse | from django.urls import reverse | ||||
| from django.utils.text import slugify | from django.utils.text import slugify | ||||
| from django.utils import timezone | from django.utils import timezone | ||||
| from comments.models import Comment | from comments.models import Comment | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | class PostComment(models.Model): | ||||
| """An intermediary model between Post and Comment. | """An intermediary model between Post and Comment. | ||||
| A PostComment should in fact only relate to one Comment, hence the | A PostComment should in fact only relate to one Comment, hence the | ||||
| OneToOne comment field. | OneToOne comment field. | ||||
| """ | """ | ||||
| post = models.ForeignKey(Post, on_delete=models.CASCADE) | post = models.ForeignKey(Post, on_delete=models.CASCADE) | ||||
| comment = models.OneToOneField(Comment, on_delete=models.CASCADE) | comment = models.OneToOneField(Comment, on_delete=models.CASCADE) | ||||
| def get_absolute_url(self) -> str: | |||||
| return self.post.url | |||||