Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 750387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:32:42+00:00 2026-05-14T14:32:42+00:00

I have a model which can be attached to to other models. class Attachable(models.Model):

  • 0

I have a model which can be attached to to other models.

class Attachable(models.Model):
    content_type = models.ForeignKey(ContentType)
    object_pk = models.TextField()
    content_object = generic.GenericForeignKey(ct_field="content_type", fk_field="object_pk")

    class Meta:
        abstract = True

class Flag(Attachable):
    user = models.ForeignKey(User)
    flag = models.SlugField()
    timestamp = models.DateTimeField()

I’m creating a generic relationship to this model in another model.

flags = generic.GenericRelation(Flag)

I try to get objects from this generic relation like so:

self.flags.all()

This results in the following exception:

>>> obj.flags.all()        
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 105, in all
    return self.get_query_set()                                                              
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/contenttypes/generic.py", line 252, in get_query_set
    return superclass.get_query_set(self).filter(**query)                                                         
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 498, in filter                    
    return self._filter_or_exclude(False, *args, **kwargs)                                                        
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 516, in _filter_or_exclude        
    clone.query.add_q(Q(*args, **kwargs))                                                                         
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 1675, in add_q                
    can_reuse=used_aliases)                                                                                       
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 1569, in add_filter           
    negate=negate, process_extras=process_extras)                                                                 
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/query.py", line 1737, in setup_joins          
    "Choices are: %s" % (name, ", ".join(names)))                                                                 
FieldError: Cannot resolve keyword 'object_id' into field. Choices are: content_type, flag, id, nestablecomment, object_pk, timestamp, user
>>> obj.flags.all(object_pk=obj.pk)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: all() got an unexpected keyword argument 'object_pk'

What have I done wrong?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:32:42+00:00Added an answer on May 14, 2026 at 2:32 pm

    You need to define object_id_field and content_type_field when creating GenericRelation:

    flags = generic.GenericRelation(Flag, object_id_field="object_pk", content_type_field="content_type")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which models all categories and they can be ordered hierarchically.
I have a model which has a certain behaviour implemented. class X { ....
I have a one-to-many relationship within my class model. Example: A single role can
I have models as follows: class Place(models.Model): name = models.CharField(max_length=300) class Person(models.Model): name =
I have a Delphi 2006 app which can pop up a modal dialog in
I have model Foo which has field bar. The bar field should be unique,
I have django model which consist of parent child relationship filed I want to
I have a model which defines a property with either markdown or html content.
I'm using ASP.NET MVC and have a model which has an image (byte array)
I have a model Task which will HABTM many TaskTargets. When it comes to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.