Filter data in django admin page - django

I have a django project, in one of admin pages I'm adding data to the table
And I want after I choose one of themes, in Students name will be only students enrolled for this theme. How I can filter them by theme name?

Django does not do this out of the box. One third-party package I often see recommended to accomplish this common task (as opposed to writing your own ajax to do it) is django smart selects.

Related

Individual product detail pages with django cms

I have an e-commerce app based on Django. The product model contains basic fields like name, brand, short description, etc. So far, I only have a "generic product detail page" that displays these information for each product.
Now I want to create more extensive product detail pages for some of the products with django cms so that they contain more product information and seo keywords. This means that most products would just have the "generic" detail page and some have a more extensive version.
I am using a url path like mydomain.com/products/product-slug and the view finds the respective product to be displayed using the product-slug. So far, this "/products/..." path is handled outside of the django-cms url namespace.
I am rather new to django cms and unsure how I should handle this project. My first idea would be:
Add empty django-cms placeholders to the generic detail page
Include the /products/... path in the django-cms namespace
Run a script that creates a page in django-cms for each individual product (whenever a new product is added to the database, a new django-cms page must then be added as well programatically)
Go to the products of high interest and add additional content with django-cms editor
Do you have any other ideas how I could handle this task?

How to select and delete multiple objects on Wagtail admin UI?

What I wanted should be the so-called bulk-operations, i.e. on Django admin, for a Django model there could be many objects created, and we can select multiple of them and delete.
However, when I registered Django models in Wagtail, the Wagtail admin doesn't show anything similar to Django bulk operations.
And I searched for a while, looks like bulk operations are not supported in Wagtail admin?
Any other alternative we could use for Wagtail?
As of Wagtail 2.9, I don't think it's possible to bulk select pages, but you can do so with snippets.
You can submit a feature request regarding bulk selections in page lists on GitHub, but search first if such a request already exists before creating a new one.

How to use Django Rest API in Django normal project for autocomplete using Select2?

In my Django project, I have a model named Product. The model consists of products which have following entities:
name, id, price and so on.
In my project, an admin can add a new/old product anytime.
Now, for searching, I want to add autocomplete. I want to use Select2.
So users don't have to memorize the name of the products. To do that I found out here in the Select2 doc
that :
Select2 comes with AJAX support built in, using jQuery's AJAX methods
With this, I can search an API and fetch the data to show the users in autocomplete search field.
My Question:
Should I create a Django rest API and use that API to store products and fetch the data?
1.1 Would it be wise?
1.2 Is it possible to make a rest API within a normal Django project? If not then how to do that?
Or should I just use a normal urls.py and querying the result from
Select2 ajax function to that urls.py and to a custom query.py and
fetch the data directly from the database?
I don't think using rest framework with normal Django project would cause any problem. You are just adding some extra urls, that's all. It won't cause any problem to your project. Moreover, you can use the API to get json data of various models.
Hope this helps.

Custom [admin] interfaces with Django?

I've been playing around with python/django for the last couple of weeks and whilst the overall structure and makeup of the framework is making sense I'm rather confused on how to create advanced interfaces (in relation to tasks administrators would perform). One trivial example I'm playing around with at the moment is a bulk csv product import for different suppliers which will update various fields of a particular product (keeping track of any changes), creating items where they don't already exist and applying other business logic etc.
With the data successfully in the database and the models reflecting this I envisage a view whereby one could select a supplier from a drop down, which would load all the products silently in the background and display a datagrid on success. The user could then interact with each product individually, for example selecting would display a stacked line chart of pricing history above the datagrid and an optional fly-in panel to the right with options to update prices, add notes etc.
Are there any best practice approaches for achieving something along these lines, does one create custom views/templates or put some heavy lifting into overriding the default Django admin functionality?
Any help is appreciated, thanks in advance.
You can either:
Create a custom django admin action that will appear as an option in the changelist page dropdown menu (of the Supplier model for example.) You can then apply this action to the selected rows. You can also have intermediate pages when using admin actions
You can hook your own views into the django admin for particular models and and then overwrite the appropriate django admin templates to link the two together

form from multiple models

I need to create a form where the rows are a list of users and the columns are all the user's permissions. The models are the default django User's and django Permission's models.
How can I do this things? Are there a way to do by django forms or I must do manually with django and js?
If you just want to view this data, extract the relevant information (User and Permission instances), and then generate a table using django templates. Django intentionally does not 'bless' any css or js frameworks, so you are required to do the html yourself (using tools of your choosing).
Forms aren't going to help you here I don't think. I advise you to draw up what it is you want to see, and start figuring out what the html is going to need to look like. Forms in django are simply a mechanism for passing data between django and the user. You are free to render them how you wish.