generic-relations

Django BaseGenericInlineFormSet forms not inheriting FormSet instance as form instance related_object

十年热恋 提交于 2019-12-10 10:21:17
问题 I'm using Django 1.8 and I have an Image class that looks like this: # The `child` class class Image(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() related_object = GenericForeignKey('content_type', 'object_id') image = models.ImageField(...) def clean(self): related_class = self.content_type.model_class() # Do some validation that relies on the related_class And a "parent" class that has a GenericRelation to it: # The `parent` class

Django BaseGenericInlineFormSet forms not inheriting FormSet instance as form instance related_object

拥有回忆 提交于 2019-12-05 20:23:56
I'm using Django 1.8 and I have an Image class that looks like this: # The `child` class class Image(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() related_object = GenericForeignKey('content_type', 'object_id') image = models.ImageField(...) def clean(self): related_class = self.content_type.model_class() # Do some validation that relies on the related_class And a "parent" class that has a GenericRelation to it: # The `parent` class class Product(models.Model): ... images = GenericRelation('Image') This is my (simplified) view: from

How to traverse a GenericForeignKey in Django?

吃可爱长大的小学妹 提交于 2019-11-30 09:13:11
I'm using Django v1.9.4 with PostgreSQL 9.2.14 behind. With the following models: from django.db import models from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey from django.contrib.contenttypes.models import ContentType class Foo(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() bar = GenericForeignKey('content_type', 'object_id') class Bar(models.Model): foos = GenericRelation(Foo, related_query_name='bars') class Meta: abstract = True class BarX(Bar): name = models.CharField(max_length=10, default='bar x')

How to traverse a GenericForeignKey in Django?

柔情痞子 提交于 2019-11-29 13:53:25
问题 I'm using Django v1.9.4 with PostgreSQL 9.2.14 behind. With the following models: from django.db import models from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey from django.contrib.contenttypes.models import ContentType class Foo(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() bar = GenericForeignKey('content_type', 'object_id') class Bar(models.Model): foos = GenericRelation(Foo, related_query_name='bars')