Last active
September 18, 2015 19:17
-
-
Save victorfsf/c9e8ac2b6447c49d75c7 to your computer and use it in GitHub Desktop.
Django's Generic Foreign Key Model Mixin
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.contenttypes.models import ContentType | |
from django.contrib.contenttypes.fields import GenericForeignKey | |
from django.db import models | |
class GenericModelMixin(models.Model): | |
model_id = models.PositiveIntegerField(blank=True, null=True, editable=False) | |
model_type = models.ForeignKey(ContentType, blank=True, null=True, editable=False) | |
model_object = models.GenericForeignKey('model_type', 'model_id') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment