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 6181017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:56:48+00:00 2026-05-24T00:56:48+00:00

I need to combine two instances of a model, and the process I need

  • 0

I need to combine two instances of a model, and the process I need to go through is fairly simple. There’s no much if any normalized data in the system. To combine the two I would just need to merge the data, and set the relevant foreign_keys on any models related.

The issue comes in trying to keep the app as ‘reusable’ as possible. I don’t want to edit this module any time I add another model which might work with this one. is there a way to get a list of models with a foreign key to another specific model? and what the relevant fields are?

Also, a number of links back to this root model would be through generic foreign keys. Hoever I’m assuming finding the models linking to the root object would work on finding models linking to the ContentTypes model.

  • 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-05-24T00:56:49+00:00Added an answer on May 24, 2026 at 12:56 am

    You might be able to pull this off via introspection, but you are tightly coupling your models to the Django implementation, which could be dangerous. If you are good with that, you could do something along the lines of:

    class MyModel(models.Model):
        ## Definitions
        @property
        def related(self):
            related = []
            for attr in dir(self):
                try:
                    ## Get the class name.
                    attr_type = type(bf.__getattribute__(attr)).__name__
                    ## This is an internal type tucked away in:
                    ##     django/db/models/fields/related.py
                    ##   As best I can tell, this is only used for reverse
                    ##   relationships.
                    if attr_type == "RelatedManager":
                        related.extend(bf.__getattribute__(attr).all())
                except:
                    ## Some of the built in methods / properties throw errors,
                    ##   skip them.
                    pass
            return related
    

    Might not be the best solution, but it seems to work in testing.

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

Sidebar

Related Questions

I need to ask something is there any way combine two tables different count
I have data from two different sources that I need to combine. Some data
I have two IList<Traffic> I need to combine. Traffic is a simple class: class
I need to combine two mod_rewrite rules into one. 1) In CMS, there is
Using C++ I need to combine two distinct IDs into one 16bit integer. Then
I need to combine lines in two files, basing in the condition, that in
I need to create a table that will combine two database tables together. Both
I need to combine two 32-bit values to create a 64-bit value. I'm looking
I need to combine two URL's that both contain .Path information. I would like
I need to combine two urls, but it seems that UriBuilder doesn't support url's

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.