Django. Edit model form in popup in admin - python

Is there any ready apps for django admin, that allows to edit model in popup?
I want next functionallity:
View edit form for model in popup.
On model save - update row in list of models.
Motivation: reduce page reloads.
Also, if there any solutions oriented on massive manual data updates for django? I've taken a look at django grappelli - it improves view of data, but edit data is still not usable.
P.S.: If such kind of app is not available - I'll start open source project.

If you want to open a popup, simply create a link to your 'add' view with the following attribute on that link onclick='return showAddAnotherPopup(this);'

You can do most of what you ask there (at least point 1 and 2) using the django built in admin customisations.
Have a look at https://docs.djangoproject.com/en/dev/ref/contrib/admin/
The django admin itself already uses some things similar to this, pay special attention to the django _popup=1 variable in the request URI.
You will have to add a custom modelname_change_list.html file to provide some javascript and in the ModelAdmin override the delet_view, change_view, response_add and potentially response_change.

Related

Knowing when's best to use Wagtail Pages or Django Models for Wagtail website

I am making a website running wagtail as the CMS/backend and use Page for things that are actual web pages on the site. In addition to this I will need an Events section and I am unsure whether to make it as a Wagtail Page or Django models.Model.
The way I would like this to work for the user is to have an Events section in the admin panel using ModelAdmin so that the user can easily find and navigate to all Events, and, for those events to be displayed in various sections of the site - Home Page, Events Page, Article Page for example.
I think using Page for this and requiring the user to navigate to it (Home > Events Listing > Event Detail) each time is rather a waste of time and cumbersome as opposed to having it use ModelAdmin paired with Django models.Model and that being 1 or 2 clicks away.
Reading through my question it's obvious I am leaning towards using Django model for this, so my question is: what is the trade-off between the two? Is there a set use case for using one or the other? Would using one mean having more/less functionality over the other and what would those be?
Note: I know my question is almost identical to Guidelines for using Wagtail Pages or Django models? however it's more focused on ecommerce but most importantly it has no answer.
Use models.Model and register as a snippet because it will give you more flexibility.
As a user mentioned above, using a snippet is a great idea for what you're discussing. It's one click on the admin and they're in the event system. Then, you can just pass that model into the context for a page. Here's an example of doing this in Wagtail. See this example on adding snippets as streamfield if you wanted the customer to be able to place the events manually through the CMS.

Django ArrayField on Frontend Form?

I'm currently in the process of rebuilding my WordPress website into a full Django web app. With WordPress, I had made great use of the awesome Advanced Custom Fields plugin, and I'm struggling to get the same functionality with Django. One field in particular with ACF is called a "Repeater Field" that lets me click a button to add another row to an array.
I did manage to get something similar working with Django, but only in the Admin part. I've used this plugin "Django Better Admin ArrayField" - https://github.com/gradam/django-better-admin-arrayfield and it displays the arrayfield exactly as I want:
Django Better Admin ArrayField
How can I get this to work on the frontend of the site, like in a user-submitted form?

Adding a Non-Model Form in Django Admin

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.

Django modelform: Create new related object

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.

What are the best uses for the Django Admin app?

On the website, it says this:
One of the most powerful parts of
Django is the automatic admin
interface. It reads metadata in your
model to provide a powerful and
production-ready interface that
content producers can immediately use
to start adding content to the site.
In this document, we discuss how to
activate, use and customize Django’s
admin interface.admin interface.
So what? I still don't understand what the Admin interface is used for. Is it like a PHPMYADMIN? Why would I ever need this?
Let's say you create a model called Entry. IE an extremely simple blog. You write a view to show all the entries on the front page. Now how do you put those entries on the webpage? How do you edit them?
Enter the admin. You register your model with the admin, create a superuser and log in to your running webapp. It's there, with a fully functional interface for creating the entries.
Some of the uses I can think of -
Editing data or Adding data. If you have any sort of data entry tasks, the admin app handles it like a breeze. Django’s admin especially shines when non-technical users need to be able to enter data.
If you have understood above point, then this makes it possible for programmers to work along with designers and content producers!
Permissions - An admin interface can be used to give permissions, create groups with similar permissions, make more than one administrators etc. (i.e. if you have a login kinda site).
Inspecting data models - when I have defined a new model, I call it up in the admin and enter some dummy data.
Managing acquired data - basically what a moderator does in case of auto-generated content sites.
Block out buggy features - Also if you tweak it a little, you can create an interface wherein say some new feature you coded is buggy. You could disable it from admin interface.
Think of the power this gives in a big organization where everyone need not know programming.

Categories

Resources