django-admin

Django admin site: How does the Add User page work (more fields on edit)?

南笙酒味 提交于 2020-01-13 07:00:28
问题 I was wondering how they made it possible to display more fields in the User page of the Django admin site. If you create a new User you only have some basic fields to fill in, but if you reopen that user (edit mode) then you see a lot more fields to fill in. I'm trying to achieve the same, I had a look at the add_form.html template but I can't really get my head around it. I guess I'm looking for a way of specifying different fields = [] sets based on the edit status of the document. Thanks!

Django Admin - how to prevent deletion of some of the inlines

醉酒当歌 提交于 2020-01-13 06:35:16
问题 I have 2 models - for example, Book and Page. Page has a foreign key to Book. Each page can be marked as "was_read" (boolean), and I want to prevent deleting pages that were read (in the admin). In the admin - Page is an inline within Book (I don't want Page to be a standalone model in the admin). My problem - how can I achieve the behavior that a page that was read won't be deleted? I'm using Django 1.4 and I tried several options: Override "delete" to throw a ValidationError - the problem

using User.objects.get_or_create() gives invalid password format in django?

我的梦境 提交于 2020-01-13 03:00:13
问题 python manage.py shell >>> from django.contrib.auth.models import User >>> u=User.objects.get_or_create(username="testuser2",password="123") >>> u (<User: testuser2>, True) seems it created the User properly. but when I logged into admin at http://127.0.0.1:8000/admin/auth/user/3/ , I see this message for password Invalid password format or unknown hashing algorithm. Screenshot is attached too. why is it this way and how to create User objects from shell. I am actually writing a populating

How do you add a new entry into the django admin index?

夙愿已清 提交于 2020-01-13 02:09:27
问题 I'm working on a Django project, and I've created some custom admin views using the get_urls override method described in the documentation. It works perfectly. There is just one problem. There is no way to get to this custom admin view unless you already know the URL. There are some ways I already know of to add a link to this view somewhere in the admin, but none of them are satisfactory. I want a link to the custom view to appear in the model listings right with all the model admins. I

Add custom html between two model fields in Django admin's change_form

做~自己de王妃 提交于 2020-01-12 09:08:20
问题 Let's say I've two models: class Book(models.Model): name = models.CharField(max_length=50) library = models.ForeignKeyField('Library') class Library(models.Model): name = models.CharField(max_length=50) address = models.CharField(max_length=50) tel = models.CharField(max_length=50) Is there a nice way to add some html(a readonly input field) between name and address in the Library change_form template?. I'm doing it overriding admin/includes/fieldset.html but it's getting messy and I can't

Add custom html between two model fields in Django admin's change_form

萝らか妹 提交于 2020-01-12 09:08:07
问题 Let's say I've two models: class Book(models.Model): name = models.CharField(max_length=50) library = models.ForeignKeyField('Library') class Library(models.Model): name = models.CharField(max_length=50) address = models.CharField(max_length=50) tel = models.CharField(max_length=50) Is there a nice way to add some html(a readonly input field) between name and address in the Library change_form template?. I'm doing it overriding admin/includes/fieldset.html but it's getting messy and I can't

Storing file content in DB

旧时模样 提交于 2020-01-12 07:12:02
问题 I am making a model in which i have a FileField . I want to store the file content in a database column, instead of file path. Any suggestions? 回答1: Disregard the naysayers. If you want to have full control over your content, put the files in a blob field in the database. I generally also keep the filename in a separate field, so I can reconstruct the file as necessary (that way you keep the extension, which ties it to a file type in most operating systems). Be sure to store the actual blob

Admin page on django is broken

本秂侑毒 提交于 2020-01-12 04:25:44
问题 I've set up a django project with an admin page. It worked perfectly for the first couple weeks of development, didn't use the admin page for a while, and when I came back to it, the admin page was broken. No matter what I do, it won't allow me to log in. After entering username and PW, the admin page always says: Please enter a correct username and password. Note that both fields are case-sensitive. I've checked the DB: the superuser exists and has is_active, is_superuser, and is_staff all

Admin page on django is broken

眉间皱痕 提交于 2020-01-12 04:25:34
问题 I've set up a django project with an admin page. It worked perfectly for the first couple weeks of development, didn't use the admin page for a while, and when I came back to it, the admin page was broken. No matter what I do, it won't allow me to log in. After entering username and PW, the admin page always says: Please enter a correct username and password. Note that both fields are case-sensitive. I've checked the DB: the superuser exists and has is_active, is_superuser, and is_staff all

Django: TemplateSyntaxError: Could not parse the remainder

烈酒焚心 提交于 2020-01-12 04:11:31
问题 I am getting this issue when I type localhost:8000/admin/ . `TemplateSyntaxError: Could not parse the remainder: ':password_change' from 'admin:password_change'. The syntax of 'url' changed in Django 1.5, see the docs. Here's part of my settings.py : INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'grappelli', 'filebrowser', # Uncomment the next line to enable