How would I add a rich-text HTML content editor in my Django admin view?
For example, if I want to change the content on my homepage, what python code would I have to input for the HTML to be displayed when I log into the admin portal?
I want to be able to view all of my pages (hopefully even be able to add/delete them), and edit the content directly from the admin view. Similar to something like this:
http://feincms-django-cms.readthedocs.org/en/latest/_images/item_editor_content.png
I appreciate any and all help! Thank you!
The html shown there is there cuz it is in the database. If what you want is a cms, there are several of those for django like django-cms, wagtail, mezzanine among others.
If, on the other hand, you have a model already and want to display it in the admin, you can register it:
from django.contrib import admin
from myproject.myapp.models import Author
class AuthorAdmin(admin.ModelAdmin):
pass
admin.site.register(Author, AuthorAdmin)
In that example, the Author model will show up in admin for edition.
In the last case, where you already have your model registered but you want to have a WYSIWYG editor, check the django-grid for that kind of package and find one suitable, or install one manually.
You have several options in case you want to try the second approach: ckeditor, tinymce, etc.
Related
I have done a django web app in which users can input some data. I have created a super user and as the admin of the app I can see the data input by users which is fine for name and not sensitive data but I do not want to be able to see their sensitive data such as health data.
I have used the encrypt module from django_cryptography.fields as follow:
health_data = encrypt(models.IntegerField(default=140))
I figured out that if I am looking at the database from external script or simple DBbrowser, it works well as I cannot see the sensitive data. But I understood that this is seamless in the django admin: in django admin page it is decrypting before it is rendered.
So I am ok with the encrypt data which is additional safety but this was not my first goal. I want to have the super user but I want that I am not able to see their sensitive data. Do you have any ideas ? I appreciate your time reading.
As suggested here I changed my admin code from this:
from django.contrib import admin
from .models import MyModel
# Register your models here.
admin.site.register(MyModel)
to this:
#admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
# avoid admin can see the sensitive data in admin page
fields = ("non_sensitive_field1", "non_sensitive_field2",...,)
By this way I customize the rendered fields in admin page. I cannot see anymore the sensitive data from users in the admin page which is the behavior I wanted.
This is probably something simple, but I'm just not seeing it. So I started a new app called proposals. The following I entered into the app's models.py:
from django.db import models
class Proposal(models.Model):
name = models.CharField(max_length=200)
I then entered the following into admin.py:
from django.contrib import admin
from proposal.models import Proposal
class ProposalAdmin(admin.ModelAdmin):
pass
admin.site.register(Proposal, ProposalAdmin)
This seems incredibly straightforward, right out of the Django docs, but the "Add" and "Change" options for this admin are not appearing. They do appear for everything else, but not this particular admin. Any ideas on what might be causing this?
UPDATE
I'm continuing to check into this, and it's not a permission issue. The permissions are all set to true for add / change / delete. The template that generates the admin page requires a model.add_url for an "Add" link and model.admin_url for a "Change" link. These attributes are missing for some reason. Thus no links. Why they are missing is the big question.
UPDATE
I finally discovered what was going on here. An app which didn't need the add / change links was listed in the installed apps prior to this new one. Whatever it's author did to cause these links not to appear ended up being inherited by all other apps that followed it in this list. When I moved this new app above this one, the links appeared. I didn't even know that it was possible for apps to affect each other like this, but that is something to look for in the future.
I am new to Django as well as Python. I am trying to build a Employee management System using django framework.
Till now I was able to build models and show the models in admin module. Now I want to show user a user profile and able to update their details.
I am still in starting phase of the project. What I want to do is, I want show the profile page in the below format i.e similar to admin page look.
But till now I was able to get like below
Is it possible to make profile page of each employee look just like admin page look? which has collapsible options as well
You will need to write your views as well as create you template folder with the relevant template tag.
I believe that is what will get you what you want.
The models you create shows the database columns and rows you want Django to create.
Please check the link below assuming you are using Django 1.6:
https://docs.djangoproject.com/en/1.6/intro/tutorial03/
The collapsible part of Django admin, is made with JavaScript (jQuery) & CSS.
If you want your page to be dynamic, use JavaScript.
If you want to make it more beautiful, use CSS.
I want to do the following:
I want to add a "Refresh" link at the top of the django admin page for a model. How can I do that? I want when people click on Refresh they go to another page that gets data from Google analytics API.
How can I add a link at the top of the admin page for a model? Thanks!
What I tried:
I tried overriding the change_list template for the django admin, but that did not work.
Overriding the change_list template is really your only choice. Did you get errors? or did your content not show up? The hierarchy of your templates directory is directly related to how/where Django looks for templates.
Double check the documentation on overriding admin templates. You may have made a simple mistake: https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#overriding-admin-templates
I'm using the Django Admin module. It displays a list of models to edit by app. I would like to add another form to this list. It won't edit a specific model, but it will edit settings that are stored in the database. Is this possible?
You may check out Django Live Settings. It was split out of the Satchmo project and looks to do what you're looking for.
Otherwise, you may look into Overriding the Django Admin Templates. You could just override the index template and add your links to the bottom.