Django: publishing and unpublishing posts - django

I have a basic Django blogging application with the fields such as textfield, datetime, imagefield, slug etc. I want to have a feature where I can publish and unpublish posts in the admin interface(with the help of checkbox). How can this be done?

Add a BooleanField that describes whether or not the post is published, and check the value of this field in your views.

Related

No formatting supported by TextField in django admin panel

I have Post model and have it registered in admin. It has description of TextField() but while adding new post from admin panel, description area does not support newline or <br> or any kind of formatting.
I have no usage of forms and only way to add post is through admin panel.
https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#linebreaks
this reference worked for me.

In django, can I show post's permalink in admin page?

I have a model called Post for my Blog application in Django. I have a slug field that is prepopulated by the title field. (I also use the get_absolute_url method, if that matters). What I want is to be able to see the permalink, of course without being able to edit it! Just readonly. I also believe that this field will be empty when I create a post, so only visible-active when I update a post.
Thanks in advance.

Get the site_id of the user_id in Django?

I'm really struggled by this. I looked through the Django documentation and I couldn't find a method to get the site_id of the currently logged in user_id with Sites framework.
I want to build a blogpost form and I wan't to include the site_id so that the content that the user publish will go to that particular site_id.
The user will only have permissions to publish to one site_id.
To clarify:
Publish content to the site_id that the user_id belongs to.
Is there a way to do this?
A user does not belong to a site. A request does.
If, somehow, in your Django project sites are owned by users, then you should add a new field to your User model. Something like this:
class MyUserModel(...):
...
blog = models.OneToOneField(Site)

Django, filter users by group in a model foreign key

I have a model for a blog post where the owner of the post is a foreign key to User. With that model any user can own a blog post. I would like to change it so that only the users in a certain group -let's call it 'bloggers'- can own a blog post object. Ideally it should appear in the admin too, I mean in the blog post admin right now the menu for 'owner' lists all the users, it should only list the ones in the 'bloggers' group.
How do I do that with Django 1.3?
Use limit_choices_to paramether in your ForeignKey definition like this:
author = models.ForeignKey("auth.User", limit_choices_to={'groups__name': "bloggers"})

displaying list of registered user in django-admin

My Book model has an author attribute which today is simply a CharField. The value for author should be one of the registered users of my Django site. When creating a new Book object in Django admin, I would like author to be displayed as a combo box showing all registered users. How would I go about achieving this?
You can make your author attribute a foreign key to django.contrib.auth.models.User and use limit_choices_to.