1

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 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.