Skip to content

Instantly share code, notes, and snippets.

@axil
Last active May 30, 2020 19:20
Show Gist options
  • Save axil/b8b354c0387150ccd19c072c6214470a to your computer and use it in GitHub Desktop.
Save axil/b8b354c0387150ccd19c072c6214470a to your computer and use it in GitHub Desktop.
foreignkey update
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