generic-foreign-key

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')

sqlalchemy generic foreign key (like in django ORM)

纵然是瞬间 提交于 2019-11-28 17:59:20
Does sqlalchemy have something like django's GenericForeignKey? And is it right to use generic foreign fields. My problem is: I have several models (for example, Post, Project, Vacancy, nothing special there) and I want to add comments to each of them. And I want to use only one Comment model. Does it worth to? Or should I use PostComment, ProjectComment etc.? Pros/cons of both ways? Thanks! The simplest pattern which I use most often is that you actually have separate Comment tables for each relationship. This may seem frightening at first, but it doesn't incur any additional code versus

sqlalchemy generic foreign key (like in django ORM)

 ̄綄美尐妖づ 提交于 2019-11-27 10:58:39
问题 Does sqlalchemy have something like django's GenericForeignKey? And is it right to use generic foreign fields. My problem is: I have several models (for example, Post, Project, Vacancy, nothing special there) and I want to add comments to each of them. And I want to use only one Comment model. Does it worth to? Or should I use PostComment, ProjectComment etc.? Pros/cons of both ways? Thanks! 回答1: The simplest pattern which I use most often is that you actually have separate Comment tables for