generic-foreign-key Questions

2

symbol.py class Symbol(BaseModel): name = models.CharField(max_length=30,) class Meta: abstract = True class StockSymbol(Symbol): market = models.CharField(max_length=10,) my_daily_price = ...
Indomitability asked 4/2, 2018 at 6:53

3

Solved

I have the following: target_content_type = models.ForeignKey(ContentType, related_name='target_content_type') target_object_id = models.PositiveIntegerField() target = generic.GenericForeignKey('...
Somatotype asked 22/6, 2012 at 15:32

1

I am trying to restrict GFK to be pointed to objects of a few models only, and I thought CheckConstraint will be a great way to do this, however I get this error class ManualAdjustment(Model): co...

3

Solved

I'm creating a custom commenting system which can attache comments to any model using the contenttypes GenericForeignKey. class Comment(models.Model): body = models.TextField(verbose_name='Commen...

3

I want to create data migrations for a model(Comment) which has a GenericForeignKey relation. My model was made according to django documentation for contenttypes. Models: ... class NiceMeme(mode...
Doroteya asked 31/10, 2015 at 0:6

2

Solved

I must be really misunderstanding something with the GenericRelation field from Django's content types framework. To create a minimal self contained example, I will use the polls example app from ...

1

I've been trying to display a GenericForeignKey in the Django admin but can't get it working. I have a FullCitation class that can be linked to either a NonSupportedProgram or a SupportedProgram cl...

1

Solved

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 fro...

0

I need sort functionality on a GenericForeignKey's field on list display. models.py class DealPayment(models.Model): product_type = models.ForeignKey(ContentType) object_id = models.PositiveIn...
Mellifluent asked 28/12, 2015 at 6:10

3

Solved

I've pored over the Django docs regarding the contenttypes framework several times, and I simply don't understand it well enough to implement generic relations in my project. I've looked for online...

2

Solved

I have the following conceptual models: class GenericAbstractBase(models.Model): name = models.CharField(max_length=255) staff = generic.GenericRelation( "Staff", content_type_field="content_t...
Isaacisaacs asked 5/3, 2014 at 14:37

4

Solved

I need to perform a datamigration of a model Answer in app Question. In that script there is a dependency such that I need to create an instance of a model Chapter which is in the app Journal. So, ...

1

I am using a Generic Relation on a model and trying to serialize it using Django Rest Framework. However doing the following gives me an attribute error : 'GenericForeignKey' object has no attrib...

1

Solved

I am working on an discussion app in Django, that has Threads, Posts, Replies and Votes. Votes uses Generic Foreign Keys and Content Types to ensure a user can only vote once on a specific Thread/P...

2

Solved

I'm new in using GenericForeignKey, and I couldn't make it to work in a query statement. The tables are roughly like the following: class Ticket(models.Model): issue_ct = models.ForeignKey(Conten...
Listel asked 14/8, 2012 at 20:42

2

Solved

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 sp...
Arching asked 17/7, 2013 at 14:57

1

Solved

Suppose I have a model Box with a GenericForeignKey that points to either an Apple instance or a Chocolate instance. Apple and Chocolate, in turn, have ForeignKeys to Farm and Factory, respectively...
Keek asked 17/9, 2012 at 20:51
1

© 2022 - 2024 — McMap. All rights reserved.