“Django -Inhaltstyp” Code-Antworten

Django -Inhaltstyp

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
Big Boi Blakos

Django -Inhaltstyp für Modell

ctype = ContentType.objects.get(model='user')
related_to_user = Room.objects.filter(content_type=ctype)
The Mortiest Morty

Ähnliche Antworten wie “Django -Inhaltstyp”

Fragen ähnlich wie “Django -Inhaltstyp”

Weitere verwandte Antworten zu “Django -Inhaltstyp” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen