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

  • Home
  • SEARCH
  • 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 9184267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:00:16+00:00 2026-06-17T19:00:16+00:00

Ok so this may be really easy for someone else to solve but i’m

  • 0

Ok so this may be really easy for someone else to solve but i’m really confused on how to go about solving this.

So to start, i have a model A that has multiple fields that have many-to-many relationships to specific tables. So for example

class A(models.Model):
    field1 = models.ManyToMany('field1Collection')
    field2 = models.ManyToMany(field2Collection')

class field1Collection(models.Model):
    description = models.TextField()

class field2Collection(models.Model):
    description = models.TextFIeld()

Anyway this is what i’m trying to accomplish. I need to write another model that can hold a ranking system. So for example, i want to create a record where i can define

I have x number of ranks (3 for example):

  1. field1Collection Object 3
  2. field2Collection Object 6
  3. field1Collection Object 2

So i basically want to be able to select objects from my field1Collection and field2Collection tables and assign them ranks. I tried thinking up schemes using foreignkeys and m2m fields but they all go wrong because the model needs to know “ahead” of time which collection set i need to reference. Does this many sense? can anyone help?

  • 1 1 Answer
  • 0 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-06-17T19:00:18+00:00Added an answer on June 17, 2026 at 7:00 pm

    You can solve this using GenericForeignKey relationship

    from django.db import models
    from django.contrib.contenttypes.models import ContentType
    from django.contrib.contenttypes import generic
    
    class RankItem(models.Model):
        rank = models.IntegerField()
        content_type = models.ForeignKey(ContentType)
        object_id = models.PositiveIntegerField()
        content_object = generic.GenericForeignKey('content_type', 'object_id')
    
        def __unicode__(self):
            return self.rank
    

    A normal ForeignKey can only “point to” one other model, which means that if the RankItem model used a ForeignKey it would have to choose one and only one model to store tags for. The contenttypes application provides a special field type which works around this and allows the relationship to be with any model

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem really silly to you, I admit, but when discussing the Model-View-ViewModel
This may be a duplicate question, but really don't know how else to word
This may seem like a really easy question to answer, but I'm just a
this may be a easy question, but I really need a light to go
I fear this may be a dumb question/easy fix, but have been stuck for
OK, this may be really simple, but it is Friday and it has been
this may be a really n00b question, but if your list of params contains
This may be a really silly question, but it just crossed my mind and
This may be a really dumb question but I'm just starting to learn the
This may be a stupid question but I have a code with the following

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.