When deleting an item from the Django Admin page, the delete form shows:
Summary
Objects
The Objects list shows all the objects and their related objects. The list is pretty huge and difficult to navigate when deleting multiple records.
Is there a way to hide the "Objects" list from the delete form in Django?
I have looked around, but the only option I have found is to override the template. Is it possible to achieve this through ModelAdmin?
The options as you've found are to either override the template (and likely the view itself to avoid the additional queries) or disable the existing action and create your own version.
Related
I am trying to add a non-model form in django admin interface and am not able to find any particular way to do it. This form would do some processing and change some data in the DB. But this is not related to a particular Model and should stand out. This form should not be available for the user to use.
One thing I can do is add the form to the general view and prohibit using permissions but I was thinking since django admin interface already exists, it would be better to add that to the django admin interface.
Is this possible to do in Django?
You can add arbitrary views that within a ModelAdmin that do whatever you want. See the documentation for ModelAdmin.get_urls. You can do the same at a higher level by defining AdminSite.get_urls.
I'm new at Django and I'm creating a small app that has some really simple models but uses custom users. Now I wish to customize the object listing in the administration for some users. What I wish to do is customize the object listing in
myserver/admin/myapp/myobject but I haven't found which should I extend to do so. I'd be thank to know where should I look.
I would take a thorough look through the Django admin documentation. They do a pretty good job at explaining how to customize the list display.
https://docs.djangoproject.com/en/dev/ref/contrib/admin/
I would focus on learning the following,
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display
This will alter the fields being shown for each row in the list.
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter
This will allow you to filter your data which is shown within the list.
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields
This will allow you to add a search box which will let you search against the objects within the list.
I'm trying to do something a little bit different than other Django admin thumbnail questions here. I have two models that reference my Photograph model either via ForeignKey or ManyToMany and would like to be able to see the available photos in the admin interface as thumbnails instead of by their title. I've tried using an admin_thumbnail method that returns the appropriate HTML as a tag (I've used this elsewhere with success) but to no avail. The list of Photograph objects is using their __unicode__ return value to populate the list, so I tried having __unicode__ return mark_safe(the HTML string) but the list items all end up with empty strings. Any ideas? I'm bad with widgets and I'm hoping a custom widget isn't my only option here.
I've been searching stack overflow and google for a solution for over an hour now, and I can't seem to find something that, in my opinion, should be easy to obtain (as it's a common use case).
I've checked this thread, and a few others, but I haven't been able to find a real, easy solution:
Django modelform: is inline adding related model possible?
Anyway, say I have a model with three related entities, two foreign keys and a many-to-many related class. Now, I have a ModelForm which displays these in comboboxes and lists, but what I need is that "+" button next to these elements (as seen in the admin interface).
I want the plus to take me to a new form, for that particular entity, allow me to submit the new information, create the database entry, take me back to my original form and have the newly added entity selected in the combobox. I'm really hoping the django ModelForm Meta class has an attribute that I can't seem to find which enables exactly this.
This isn't really a django question.
This has to do with presentation of a particular widget in an html document, and that is governed by either the HTML markup, CSS, or javascript.
Django is a server side application and is primarily responsible for creating a valid http response and receiving a valid http request (of course, there is a lot that happens in the interim and that is why django is so big) but it's not a "one toolkit to kill them all" app.
I think you want to look at bootstrap: http://getbootstrap.com/
Jquery UI: http://jqueryui.com/
Or some combination of the two.
You can also just mark up the document yourself with a stock img or something.
However, if you want to do it exactly how the admin does it, just go into django.contrib.admin and examin the code to figure out how the django developers did it. I believe they are just using Jquery UI and some manual markup to accomplish that.
I have a requirement where one user creates an 'instance' of an object via a ModelForm. Another user of a different group has access to read all of the fields of the form, but has to update only one field. Think of a student who creates an exam object. Then a teach pulls up the exam and just needs to put in a grade, the rest of the exam is read only.
What's the best way to do that? Should I just query for the object, and display each field individually, then create a form (not a ModelForm?) for just the one field?
Should I just query for the object, and display each field individually, then create a form (not a ModelForm?) for just the one field?
This is probably the best way to go about it. Note you can use a ModelForm for the teacher form, see the Django documentation on using a subset of fields on a model form. You will have to display all the other fields manually in your template, but you should probably have a separate template for this view (I would use separate views as well).
You could find some code for a read only field on Django Snippets, but generally it's better to be explicit about what fields you are updating from each view. This is likely to be more trouble than it's worth.