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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:45:26+00:00 2026-06-14T21:45:26+00:00

I have two Model class User(models.Model) id = models.IntegerField(primary_key=True) username = models.CharField(max_length=20, unique=True) class

  • 0

I have two Model

class User(models.Model)
    id = models.IntegerField(primary_key=True)
    username = models.CharField(max_length=20, unique=True)

class Blog(models.Model)
    id = models.BigIntegerField(primary_key=True)
    user_id = models.IntegerField()
    ...

Because User in db User, and Blog in db Blog_1, Blog_2…Blog8, so without ForeignKey

In bloglist views, I want to show blogs with username.
How do it with one query? or must have multi queryset?
Blog.objects.all() get the user_id, and query every username by user_id ?

And bloglist views show the blogs from the user following, I have a blogid list, but blogs from multi db, so:

for id in blogid_list
    Blog.objects.get(pk=id).using('Blog_%d' % (id % 8))

How combine in one list?
I think the code is inefficient, any Suggestions?

  • 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-14T21:45:27+00:00Added an answer on June 14, 2026 at 9:45 pm

    You need to get the user_id as an integer and then query your blog-database in a second step.

    Django does not support cross-database relationships. See the docs here

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

Sidebar

Related Questions

I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event =
I have two models: class Contact(models.Model): name = models.CharField(max_length=255) class Campaign(models.Model): contact = models.ForeignKey(Contact,
I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
For Django 1.1. I have this in my models.py: class User(models.Model): created = models.DateTimeField(auto_now_add=True)
I'm using Django and have two classes: class PR(models.Model): Jq = models.ForeignKey(JQ) user =
I have these models class User(models.Model): user_name = models.CharField() ph_number = models.CharField() class ExamPaper(models.Model):
Here two of my model classes: class DashboardVersion(models.Model): name = models.CharField(_(Dashboard name),max_length=100) description =
I have two models class Friend(models.Model): me = models.ForeignKey(User) friend = models.ForeignKey(User) remark =
I have two models: class User end class Message belongs_to :sender, :class_name=> 'User' belongs_to
I have two models: User and Teacher : class User < ActiveRecord::Base attr_accessor :password

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.