Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django content type

from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models

class TaggedItem(models.Model):
    tag = models.SlugField()
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey('content_type', 'object_id')

    def __str__(self):
        return self.tag
Comment

get ContentType with django get_model

apps.get_model('contenttypes', 'ContentType')
Comment

django content type for model

ctype = ContentType.objects.get(model='user')
related_to_user = Room.objects.filter(content_type=ctype)
Comment

PREVIOUS NEXT
Code Example
Python :: IndexError: invalid index to scalar variable. 
Python :: what is attribute in python 
Python :: ttktheme example 
Python :: disable sns plot python 
Python :: pandas disply options 
Python :: symmetrical sum python 
Python :: python minecraft server python gui 
Python :: sns boxplot ylabelsize 
Python :: reverse a string in python 
Python :: saving model 
Python :: log in python 
Python :: pkl save multiple files 
Python :: list all placeholders python pptx 
Python :: Missing data counts and percentage 
Python :: acces previous index in cycle python 
Python :: python wheel 
Python :: MNIST model 
Python :: conditional relationship sqlalchemy 
Python :: python decomposition facteur premier 
Python :: pandas convert string to numpy array 
Python :: django collectstatic with auto yes 
Python :: comment transformer un chaine de caractere en liste python 
Python :: convert pdf to excel python 
Python :: remove grid in imshow 
Python :: pigeonhole sort python 
Python :: python float to int 
Python :: min stack in python 
Python :: python get image RGB data from URL 
Python :: convert math equation from string to int 
Python :: PySimpleGUI multifiles select 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =