modeladmin

Wagtail: how to set calculated fields (@property) title in admin

不羁岁月 提交于 2021-01-29 14:38:58
问题 I use ModelAdmin module for my models in Wagtail. I have @property fields in models, where I return some annotated data and display it Index and Inspect Views in Admin. But Wagtail set title of such fields as field name in model. In regular field I use verbose_name to set nice title, how can I change titles for property field? 回答1: You have to create your own ReadOnlyPanel as it is not possible with Wagtail. mypanel.py from django.forms.utils import pretty_name from django.utils.html import

Django: accessing the model instance from within ModelAdmin?

梦想与她 提交于 2020-01-09 06:04:47
问题 I've got a model for Orders in a webshop application, with an auto-incrementing primary key and a foreign key to itself, since orders can be split into multiple orders, but the relationship to the original order must be maintained. class Order(models.Model): ordernumber = models.AutoField(primary_key=True) parent_order = models.ForeignKey('self', null=True, blank=True, related_name='child_orders') # .. other fields not relevant here I've registered an OrderAdmin class for the admin site. For

silverstripe dopublish function for ModelAdmin managed Pages

↘锁芯ラ 提交于 2020-01-06 19:34:06
问题 in the silverstripe backend I´m managing certain PageTypes via a ModelAdmin. That works fine so far, the only thing i can´t figure out is how to make a Page being "Published" when saving it. Thats my code: class ProjectPage extends Page { public function onAfterWrite() { $this->doPublish(); parent::onAfterWrite(); } } At the moment I can still see the ModelAdmin-created Pages in the Sitetree and I can see they are in Draft Mode. If I use the code above I get this error: Maximum execution time

change list display link in django admin

我与影子孤独终老i 提交于 2019-12-31 09:16:50
问题 I am trying to change the link for an object in the django admin list display. Here is what I have so far: class FooModelAdmin(admin.ModelAdmin): fields = ('foo','bar') list_display = ('foo_link','bar') def foo_link(self,obj): return u'<a href="/foos/%s/">%s</a>' % (obj.foo,obj) domain_link.allow_tags = True domain_link.short_description = "foo" This produces another link within the original list display link e.g. <a href="/admin/app/model/pk/"><a href="/foos/foo/">Foo</a></a> 回答1: The

Wagtail ModelAdmin read only

China☆狼群 提交于 2019-12-22 09:38:18
问题 Using Wagtails Modeladmin: Is there any way to disable edit & delete options leaving only the inspect view? A possible approach that I can think of, is extending the template, removing the edit & delete buttons and then somehow disable the edit and delete view. Is there any cleaner approach? EDIT: Thanks to Loic answer I could figure out. The PermissionHelper source code was also very helpful to figure out the correct method to override. Complete answer for only showing inspect view class

How do you unregister a model in wagtail modeladmin?

∥☆過路亽.° 提交于 2019-12-20 01:41:50
问题 I need to do the equivalent of... 'admin.site.unregister(Value)' but for a model registered with wagtailmodeladmin using 'modeladmin_register(Value)' in wagtail_hooks.py. How do you do that? 回答1: I know this is an old question, but the short answer is "There is no unregister equivalent". In standard Django, all the models you see in Django's admin area have been registered in a similar fashion, so unregister makes sense there. In Wagtail, the admin area is completely custom, and 'modeladmin'

Disable link to edit object in django's admin (display list only)?

大憨熊 提交于 2019-12-18 10:13:32
问题 In Django's admin, I want disable the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields). I see that Django has the ability to choose which fields display the link, however, I can't see how I can have none of them. class HitAdmin(admin.ModelAdmin): list_display = ('user','ip','user_agent','hitcount') search_fields = ('ip',

Wagtail ModelAdmin. Several sections for custom User

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 16:57:21
问题 I'm trying to set up Wagtail for existing custom User model. As per requirements several User pages should be available, representing different types of users (Regular, Manager, etc) I tried to make separate ModelAdmin for each case, overriding get_queryset for filtering by user type. But it looks like all of them show the first definition of ModelAdmin, as all of them has model - User Then I tried to use Proxy model, in this case there is no display at all, as Wagtail seemingly doesn't

Create another model objects in django admin within a for loop

百般思念 提交于 2019-12-12 19:40:55
问题 I am completely new to django and was a php coder previously, so please bear with me if i am being dumb. I have three models defined in my app, Comprehension, Question, Answer. Each comprehension has multiple questions and answers defined as 'inline' in the Comprehension model. Questions are input directly by the admin, but answers would added automatically from the comprehension. What I want to achieve is, to split the comprehension in to sentences and add each sentence as an answer object

SilverStripe. Search by date-range in ModelAdmin

淺唱寂寞╮ 提交于 2019-12-11 02:21:53
问题 I have date-property in my DataObject. How can I search by date-range in ModelAdmin? For example: "search all items where date is more than 2007-13-01 and less than 2007-17-01" or "search all items where date is between 2007-13-01 and 2007-17-01" For now I can search only with GreaterTranFilter or with LessThanFilter, but not with both. class MyObject extends DataObject { private static $db = [ "Date" => "Date", ]; private static $summary_fields = [ "Date" => "Date", ]; private static