how can I get all post of users in django [closed]
2024/11/7 18:30:15
I want to get users posts but I don't know how to do it. Which I neded to use relationships. I would be appreciate if you could help me
User = a --> post 1, post 2 post 3
User = b --> post4 , post 3, post 5
I want that my project behaves like this.so, I want to query posts according to user
Answer
So the answer depends on your model setup.
For example, if your models.py looks like this:
class Post(models.Model)user = models.ForeignKey(User)content = models.CharField(max_length=500)...def __str__(self):return self.user
Then if you wanted all of the posts of the user that is logged in, you would use this code, for example, in your request you would use filter to filter out the appropriate posts that match a certain parameter (in this case user):
Im building a blackjack command line game and Ive run into a snag. The shuffle feature on my deck class object keeps coming up with IndexError: list index out of range on line 29. It is a sporadic bug…
Just trimmed this down big timeI have an overall assignment that must read a file, encrypt it and then write the encrypted data to a new file.what ive tried is this:filename=input("Enter file name…
Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…
Why is there this syntax error Multiple statements found while compiling a single statement given when I run this code? Answer and help will be super appreciated for this python newbie here
I have installed PyPDF2==2.3.0, but I still get the error below when I import PyPDF2.
The error message is:ModuleNotFoundError: No module named PyPDF2._codecs
Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 10 years ago.Improv…
Im trying to make a guess the number between 1-10 game but the while loops seems to keep running. I want to program to let the user guess a number then display if its too high or low etc then start aga…
Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…
So Ive got a string e.g "AABBCCCASSDSFGDFGHDGHRTFBFIDHFDUFGHSIFUGEGFGNODN".I want to be able to loop over 16 characters starting and print it. Then move up 1 letter, loop over 16 characters a…