Issue
I am building a website where user come and login, after login user publish articles with admin approval . I do not know how to do it. I made a user authentication system where user can login. But i do not know how to make him post data with admin approval.
Solution
Therefor you need a condition in your model to be able to query the approved objects (blog posts) to display.
A basic approach could look as follows:
Create a model to store the blog posts and its logic to the database
# models.py
class Blog_Post(models.Model):
text = models.CharField(max_length=500)
is_approved = models.BooleanField(default=False)
def __str__(self):
return self.name
Register your model in the admin so you can approve them via django-admin
from django.contrib import admin
from myproject.myapp.models import Blog_Post
admin.site.register(Blog_Post)
Create a view to only fetch blog posts that have been approved by an admin
# views.py
def get_blog_post(request):
# Only fetch the blog posts that are approved
queryset = Blog_Post.objects.filter(is_approved=True)
return render(request, 'your_html.html', {'queryset' : queryset})
Render the blog posts in your template
# your_html.html
{% for blog_post in queryset %}
<div>{{ blog_post.text }}</div>
{% endfor %}
Answered By - JSRB Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.