django-admin

Django Admin: change displayed column name in inline ManyToMany field

旧巷老猫 提交于 2020-02-21 21:20:38
问题 I try to translate Django Admin site and I have a problem with ManyToMany TabularInline . My models.py are: class Doctor(models.Model): (...) specializations = models.ManyToManyField(Specialization, blank=True, verbose_name='Specjalizacje') class Meta: verbose_name = 'Lekarz' verbose_name_plural = 'Lekarze' class Specialization(models.Model): name = models.CharField(max_length=191, verbose_name='Nazwa') class Meta: verbose_name = 'Specjalizacja' verbose_name_plural = 'Specjalizacje' And my

Django admin custom ArrayField widget

末鹿安然 提交于 2020-02-20 07:32:09
问题 The current admin widget for ArrayField is one field, with comma as delimiter, like this (text list): This isn't ideal because I would have longer texts (even 20 words) and contain commas. I could change the delimiter to be something else but that still doesn't help with unreadable content in admin. What I would like is having a list of fields, that I can alter in admin. Something similar to the following image I could use another table to solve this, but I wonder if it's possible to solve it

select multiple files in django with single filefield

巧了我就是萌 提交于 2020-02-01 09:05:28
问题 How can I select multiple files in a single fileField in django? I want to select different file formats in a single filefiled in django admin. **models.py** class FileModel(models.Model): name = models.CharField(max_length=100) file_upload = models.FileField(upload_to=settings=PATH) **admin.py** admin.site.register(FileModel,FileAdmin); In the admin I want to customize the file field to select multiple files to store in given path? Could you please help me? 回答1: You can't? The FileField was

Project not finding my reusable app's admin template override

假如想象 提交于 2020-01-25 12:33:12
问题 I have a reusable app with a directory structure like this: myapp/ myapp/ views.py models.py ...etc templates/ myapp/ template1.html ...etc admin/ index.html test/ ...testing stuff setup.py ...etc I'm overriding the index.html admin template so that I can add some additional links in {% block userlinks %} that will appear in a project's navigation when it uses my app. However, when using my app inside a project, the admin homepage still uses Django's own index.html file. The project itself

Django ModelAdmin with request/user based restrictions on the fieldsets (needs to be Thread Safe)

拟墨画扇 提交于 2020-01-25 06:28:04
问题 I have several very customized Django ModelAdmins that I would like to add extra field(s) if the user is a superuser. I found somewhere that someone said to override the get_fieldsets method like this def get_fieldsets(self, request, obj=None): fieldsets = super(PageAdmin, self).get_fieldsets(request, obj) if request.user.is_superuser: fieldsets[0][1]['fields'].insert(0,'group') fieldsets[0][1]['fields'].insert(2,'is_live') else: groups = request.user.page_groups.filter( is_live = True, ) if

Django model update or create object with unique constraint

时光毁灭记忆、已成空白 提交于 2020-01-24 16:50:51
问题 There is a model: class Proxy(models.Model): host = models.CharField(max_length=100,) port = models.CharField(max_length=10,) login = models.CharField(max_length=100,) password = models.CharField(max_length=100,) class Meta: unique_together = ("host", "port") I added batch of proxies in admin interface, and one of them is 0.0.0.0:0000, login=123, password=123. Then I add another batch of proxy, and one of them is the same 0.0.0.0:0000, but with new login=234 and password=234. Is any

Django model update or create object with unique constraint

岁酱吖の 提交于 2020-01-24 16:50:37
问题 There is a model: class Proxy(models.Model): host = models.CharField(max_length=100,) port = models.CharField(max_length=10,) login = models.CharField(max_length=100,) password = models.CharField(max_length=100,) class Meta: unique_together = ("host", "port") I added batch of proxies in admin interface, and one of them is 0.0.0.0:0000, login=123, password=123. Then I add another batch of proxy, and one of them is the same 0.0.0.0:0000, but with new login=234 and password=234. Is any

Django admin action for third party model

若如初见. 提交于 2020-01-24 10:56:07
问题 How can I add actions to the admin interface of a third party app? Example: I want to have a custom action for the model django.contrib.admin.Group . With "action" I mean the batch action of the admin list view of a model. Related docs: https://docs.djangoproject.com/en/1.7/ref/contrib/admin/actions/ 回答1: Unregister the original model admin for Group model and then register it with your own ModelAdmin : from django.contrib.auth.admin import GroupAdmin from django.contrib.auth.models import

Display Total amount in the admin interface

僤鯓⒐⒋嵵緔 提交于 2020-01-23 12:00:27
问题 I have searched, didn't find any answer. I want to get the total of inline salesitem in the admin template. I want the quantity * price of the item to be shown in the admin inline table as I add quantity. Example: models.py class Stock(models.Model): price = models.DecimalField() quantity = models.PositiveIntegerField() class Sales(models.Model): name = models.CharField() #Other fields class SalesItem(models.Model): item = models.ForeignKey(Stock) quantity = models.PositiveIntegerField()

Insert or update on table “django_admin_log” violates foreign key constraint when saving new model in admin

半腔热情 提交于 2020-01-23 07:06:18
问题 When saving a new instance of a model in the admin, I get the following IntegrityError in a traceback: Traceback: File "/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 149. response = self.process_exception_by_middleware(e, request) File "/users/dan/project/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 147. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/users/dan/project/venv/lib/python2.7/site