django-admin

Custom validation in Django admin

假装没事ソ 提交于 2020-08-21 01:55:09
问题 I have a very simple Django app in order to record the lectures given my colleagues.Since it is quite elementary,I am using the Django admin itself. Here is my models.py: #models.py from django.db import models class Lecture(models.Model): topic = models.CharField(max_length=100) speaker = models.CharField(max_length=100) start_date = models.DateField() end_date = models.DateField() I need to ensure that nobody enters the start date after the end date in the admin forms,so I read the django

Adding custom fields to Django admin

南楼画角 提交于 2020-08-05 15:23:40
问题 I have defined my model with various fields. Some of these are custom fields, which I am using to validate credit card data, using the fields.py file of my app. Source is here. class Transaction(models.Model): card_name = models.CharField() card_number = CreditCardField(required=True) security_code = VerificationValueField(required=True) expiry_date = ExpiryDateField(required=True) I have defined a ModelForm in my forms.py file. class TransactionForm(forms.ModelForm): class Meta: model =

How to prevent “Changed successfully” message when overriding save_model method

你离开我真会死。 提交于 2020-08-01 06:13:07
问题 I'm trying to let users view records in the admin but not save anything. So I'm trying to do something like this: def save_model(self, request, obj, form, change): """Override save method so no one can save""" messages.error(request, "No Changes are permitted from this screen." " To edit projects visit the 'Projects' table, and make sure you are" " in the group 'Visitor_Program_Managers'.") This works however I get two messages on the next screen: My message above first And then a "The ...

docker-compose , PermissionError: [Errno 13] Permission denied: '/manage.py'

安稳与你 提交于 2020-07-20 11:12:39
问题 After doing many research I didn't found any solution worked for me. I am trying to run command in docker-composer to start project with django-admin docker-compose run app sh -c "django-admin startproject app ." Every time I am getting the error: Traceback (most recent call last): File "/usr/local/bin/django-admin", line 10, in <module> sys.exit(execute_from_command_line()) File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command

docker-compose , PermissionError: [Errno 13] Permission denied: '/manage.py'

自闭症网瘾萝莉.ら 提交于 2020-07-20 11:11:35
问题 After doing many research I didn't found any solution worked for me. I am trying to run command in docker-composer to start project with django-admin docker-compose run app sh -c "django-admin startproject app ." Every time I am getting the error: Traceback (most recent call last): File "/usr/local/bin/django-admin", line 10, in <module> sys.exit(execute_from_command_line()) File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command

Tracking changes to Django Model instances

谁都会走 提交于 2020-07-15 00:57:26
问题 When you create or modify an object instance in Django's admin, a changelog entry is created. This is really nice for fairly obvious reasons. However my model's instances created by a normal user outside of the admin interface. No changelog is recorded to note its creation (not a huge issue) but I would like to track edits the user makes. I also want to show the user this full log (user+admin edits) in the frontend so I need a way to pull the changelog out. My question: how? Is there a one

Django admin list page takes forever to load after overriding get_queryset method

巧了我就是萌 提交于 2020-07-03 13:15:08
问题 I have this model admin - class NewsAdmin(ImageWidgetAdmin): image_fields = ['featured_image'] list_per_page = 20 list_display = ('heading', 'category', 'status', 'is_active', 'created_at', 'published_at', 'created_by', 'published_by') list_editable = ('category', 'status', 'is_active') list_filter = ('published_at', 'created_at', 'status', 'is_active', 'created_by', 'published_by',) search_fields = ('heading', 'category', 'tags', 'source') actions = [enable_object, disable_object, status

Django Admin: want to prepopulate some fields when I click the add button (+) next to a foreign key

我们两清 提交于 2020-06-25 03:24:11
问题 In the Django Admin I want to use data from the current record to populate fields for a foreign key record when I click the add (+) button next to the drop-down list. For example, I am viewing an instance of X which has fields for a , b , and c and a foreign key Y . Y also has fields for a , b , and c , so when I click on the "add" button on the X instance, I want the a , b , and c fields for the new Y instance to be populated with the values from the X instance. Obviously these fields would

How to add custom view to django admin interface?

ε祈祈猫儿з 提交于 2020-06-24 08:32:08
问题 My django admin interface looks like this: Now I would like to add a view which does not correspond to a model. I could overwrite the template of above page and add a custom link. But I think this would look ugly. Example for overwriting admin/index.html : {% extends "admin/index.html" %} {% block content %} {{ block.super }} <div class="app-sonstiges module"> .... </div> {% endblock %} But maybe there is an official way to do add a custom view to the admin interface? In my case I want to

How to add custom view to django admin interface?

回眸只為那壹抹淺笑 提交于 2020-06-24 08:32:05
问题 My django admin interface looks like this: Now I would like to add a view which does not correspond to a model. I could overwrite the template of above page and add a custom link. But I think this would look ugly. Example for overwriting admin/index.html : {% extends "admin/index.html" %} {% block content %} {{ block.super }} <div class="app-sonstiges module"> .... </div> {% endblock %} But maybe there is an official way to do add a custom view to the admin interface? In my case I want to