autocomplete-light not showing up in Django admin - django

I'm trying to install the autocomplete-light function in my admin menu. I have added the following in my admin.py. I have install the app in my settings.
class InstitutionAdmin(admin.ModelAdmin):
form = autocomplete_light.modelform_factory(Institution, exclude = [])
list_display = ('name', 'url',)
autocomplete_fields = ('name')
admin.site.register(Institution, InstitutionAdmin)
added this to autocomplete_light_registry.py:
autocomplete_light.register(InstitutionAdmin)
I don't think I need to at the autocomplete to url right? because this should show up when I go to the admin page in django? What am I missing?

Do autocomplete_light.register() for every model you want to be autocompleted in InstitutionAdmin.form.
http://django-autocomplete-light.readthedocs.org/en/master/api.html#autocomplete_light.registry.AutocompleteRegistry.register

Related

Django admin filter on edit page

On a Django admin edit page, I would like to add a little search box to be able to filter a list of tags. The field tag is a many to many field.
Is there a special trick?
you can't add search field inside the box but you can search for the same field value at the top
add this to your admin.py file
#admin.py
from django.contrib import admin
from Your_app.models import Your_model
class example_class(admin.ModelAdmin):
search_fields = ['ManyToManyFiledname']
admin.site.register(Your_model,example_class)
I found the documentation on https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.autocomplete_fields
The code below adds a search box:
class TagAdmin(admin.ModelAdmin):
search_fields = ['name']
class CompanyAdmin(admin.ModelAdmin):
autocomplete_fields = ['tags']

Django-Admin and Django-Summernote create a file field in my forms

I am customizing django-admin with summernote and so far so good, but for some reason it creates a file field in my forms which is never allowed to be empty and I can't update records without uploading dummy files. Please see attachment.
My admin.py code is:
rom django.contrib import admin
from django_summernote.admin import SummernoteModelAdmin
from .models import Post, Category, Tag
# Register your models here.
# admin.site.register(Post)
# POST
#admin.register(Post)
class PostAdmin(SummernoteModelAdmin):
""" Registers the model Post in the Admin Site """
list_display = ('title','publish','status') # Columns to display
list_filter = ('status','created','publish','author') # Filter by on right column
search_fields = ('title','body') # Search in these fields
prepopulated_fields = {'slug': ('title',)} # Prepopulate
filter_horizontal = ('tag',)
raw_id_fields = ('author',)
date_hierarchy = 'publish'
ordering = ('status', 'publish')
summernote_fields = ('body',)
How can I remove the "file" field from there?
Please help.
Many thanks.
I had this same issue today after upgrading Django-Summernote from version 0.8.11.4 to 0.8.11.5 (the current version).
Can solve two ways:
Comment out Django-Summernote -- don't use
Downgrade to version 0.8.11.4 with pip
pip uninstall django-summernote
pip install django-summernote==0.8.11.4

Adding Q Lookup to Wagtail CMS Snippets

I am building out a restaurant website and using Wagtail CMS Snippets for the owner to manage menu items. The list of menu items are getting rather long and I was wondering if there is any way to add a search input field to the Snippets admin window? Below is an annotated screenshot for visual reference. Thank you.
This can easily be solved by using Wagtail's ModelAdmin module (http://docs.wagtail.io/en/v1.8.1/reference/contrib/modeladmin/), all you need is to add this piece of code to your wagtail_hooks.py file:
from wagtail.contrib.modeladmin.options import (
ModelAdmin, modeladmin_register)
from .models import Product
class ProductAdmin(ModelAdmin):
model = Product
menu_label = 'Product' # ditch this to use verbose_name_plural from model
menu_icon = 'date' # change as required
menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
add_to_settings_menu = False # or True to add your model to the Settings sub-menu
exclude_from_explorer = False # or True to exclude pages of this type from Wagtail's explorer view
list_display = ('title', 'example_field2', 'example_field3', 'live')
list_filter = ('live', 'example_field2', 'example_field3')
search_fields = ('title',)
# Now you just need to register your customised ModelAdmin class with Wagtail
modeladmin_register(ProductAdmin)
It'll create a separate menu entry for your Products model that's customisable much like default Django Admin listing. Which means you can easily add different filters and sorters to a listing.
This is a very powerful feature and I myself don't show clients the "Snippets" section at all; it's just too simple and ugly. Instead, I create a separate ModelAdmin per snippet and this gives me the power of customisation.
The search bar will appear automatically once you set up your model to be indexed with the search system. You can do this by inheriting from the wagtail.wagtailsearch.index.Indexed class and defining a search_fields list on your model, as described here: http://docs.wagtail.io/en/v1.8.1/topics/search/indexing.html#wagtailsearch-indexing-models
(Note that if you're using Elasticsearch, you'll also need to run ./manage.py update_index to add the items to the search index.)

Adding headers to columns of admin app page in Django

I'm customizing the admin panel for my django app and saw that someone pre-1.8 was using list_display = ['join', 'email', 'timestamp', 'updated'] to add a header to the columns of his django app page and separated sections based on his model.
I've tried list_display in django 1.8 and I am failing to see any header names being posted. Is there a new command for this?
Fixed:
from django.contrib import admin
from .models import Join
class JoinAdmin(admin.ModelAdmin):
list_display = ('emails', 'timestamp')
class Meta:
model = Join
admin.site.register(Join, JoinAdmin)
Issue needed to throw in second parameter in the admin.site.register of JoinAdmin

How do you create a class using (admin.ModelAdmin) for a polling app

I am working through a Django tutorial at http://lightbird.net/dbe/todo_list.html . I completed Django's official tutorial. When I attempted to sync
from django.db import models
from django.contrib import admin
class Item(models.Model):
name = models.CharField(max_length=60)
created = models.DateTimeField(auto_now_add=True)
priority = models.IntegerField(default=0)
difficult = models.IntegerField(default=0)
class ItemAdmin(admin.ModelAdmin):
list_display = ["name", "priority", "difficult", "created", "done"]
search_fields = ["name"]
admin.site.register(Item, ItemAdmin)
The terminal came back with an error that said admin was not defined. What am I doing wrong? How do I define admin?
Update: I added the whole models file as it looks now
The Django documentation lists multiple steps that need to be done to activate the admin site:
Add 'django.contrib.admin' to your INSTALLED_APPS setting.
The admin has four dependencies - django.contrib.auth, django.contrib.contenttypes, django.contrib.messages and
django.contrib.sessions. If these applications are not in your
INSTALLED_APPS list, add them.
Add django.contrib.messages.context_processors.messages to TEMPLATE_CONTEXT_PROCESSORS and MessageMiddleware to
MIDDLEWARE_CLASSES. (These are both active by default, so you only
need to do this if you’ve manually tweaked the settings.)
Determine which of your application’s models should be editable in the admin interface.
For each of those models, optionally create a ModelAdmin class that encapsulates the customized admin functionality and options for
that particular model.
Instantiate an AdminSite and tell it about each of your models and ModelAdmin classes.
Hook the AdminSite instance into your URLconf. lists a couple of things that you must do the enable Django's admin site.
If you haven't done the first two items, syncdb might complain because it can't find the admin app itself.