Reputation: 576
So , i have a django project with 2 apps
├───Blog
post
comment
└───User
profile
user (basic authentification and profile dashboards)
blog (having basic blog models : post,comment)
I need to give the users the possbility to create one or more blogs within the same project, but i don't see how i can treat an app like a model.
The only solution i figured out , is to add a foreign key to user id for every model withn the blog app.but is there a better way ?
Upvotes: 0
Views: 65
Reputation: 2247
I think you should do that:
# blog/models.py
class Blog(Model):
owner = ForeignKey(User, related_name="blogs")
name = Charfield()
class Post(Model):
blog = ForeignKey(Blog, related_name="posts")
#Other fields ...
class Comment(Model):
post = ForeignKey(Post, related_name="comments")
#Other fields ...
Upvotes: 1