PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 19, 2022

[FIXED] how to implement an admin approval system for posting blogs in pythondjango

 October 19, 2022     admin, django, python, view     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing