Last active
May 30, 2020 19:20
-
-
Save axil/b8b354c0387150ccd19c072c6214470a to your computer and use it in GitHub Desktop.
foreignkey update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.models import User | |
from django.contrib.contenttypes.fields import GenericForeignKey | |
from django.contrib.contenttypes.models import ContentType | |
from django.db import models | |
class Book(models.Model): | |
author = models.ForeignKey(User, on_delete=models.CASCADE) | |
class Comment(models.Model): | |
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) | |
object_id = models.PositiveIntegerField() | |
author = GenericForeignKey() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment