Let's say I have a model defined as such
class BlogPost(Models.Model):
""" Defines a blog model """
blog = models.TextField()
blog_id = models.AutoField(primary_key=True)
author = models.CharField()
I want to define some method that accesses the blog posts of a certain author, say 'john doe'. How would I go about defining a method to access all of the blog posts owned by john doe, and then put their blog_id's into a python list?
def selectPostsByUser(user):
""" Implement function to select all object """
NOTE: please disregard the poor representation of the data fields. They are purely arbitrary, I just put names to remove ambiguity from the example.