I am making an app to allow a user to control a rotation of banners on their site. I have all the image stuff working. A user can upload images and captions and what not. What I am wondering is, how I would achieve some sort of configuration portion to where the user could determine how many images they want and which ones they want. So that when the view goes to the DB to get the images and the info, it is getting just the right amount and the right ones.
I suppose I could do this with a single table that is a sort of configuration table, or perhaps a single file that is edited through the admin to set config options, but maybe someone has a better idea.
You can do what you need by making a model to hold extra information that is then related to a user. Check out this section in the Django documentation, and it should get you going.
Related
I am trying to rebuild our website in Django, and I am currently facing a series of rather difficult challenges for which I am not prepared. I was hoping to get some help in the matter.
The website I am building is an online archival platform for artists called Lekha. The core of Lekha is the dashboard page (which you can check out on this link, just sign in with the email stacko#test.com and the password test if you have the patience).
On the dashboard page, users have access to a hierarchical filesystem that we would like to function like a desktop filesystem for ease of use. Users can use the filesystem to organize their 'artworks' into folders. These artworks themselves are a collection of media, along with the metadata of the artwork. To upload this media and fill in the metadata, users will use a form. If users want to edit an artwork's metadata, they can do so through an auto-populated form on the same page.
The issue that I am facing is that I am struggling to find an elegant way to make all of this happen without reloading the page. Users need to be able to add, delete, and rename folders in the filesystem without reloading the page (just like dropbox). They also need to be able to add 'artwork' database entries using a popup form, and edit 'artworks' they have created through an auto-populated form that is also served to them without reloading the page (as it is currently implemented on our existing dashboard page).
All of the Django tutorials I have seen delete items using a dedicated /delete/ page, but this would require reloading the page. Based on my research, the solution I am looking for has to do with asynchronous updating through AJAX.
I wanted to ask all the Django experts out there what the best way to go about this would be. Are there any best practices I should know about before going into this? We are building our website to be robust and scale well.
Are there any specific libraries for asynchronous stuff in Django that are best?
How do asynchronous websites scale if we have several users on them at the same time, and should I write the backend in any specific way to account for potential scaling issues?
What is the difference between ASGI and WSGI?
Are there tools that I can use such as htmx to make my life easier?
I am having some struggles how does exactly django.admin.LogEntry objects are created.
Consider the following scenario:
I have a bunch of functions which take a csv file with data that allow me to create multiple objects at one call (just iterate through the file, use the data and if data in given row is correct: create a Model instance). I want to make sure that that each of that creation will be logged.
The question is: django docs are not very descriptive on how does LogEntry works and I am not sure if such actions (not taken in the admin panel itself) will be logged there. Also: will the LogEntries be created for the related objects or I have to trigger them manually?
Does anybody got any experience with such scenarios and can share thoughts about it?
The LogEntry model is in the Admin package and only used by Django admin by default. It is used in the admin layer and not model layer when saving objects. if you want to use it outside the admin, then you will have to manually create the entries yourself. That also means the admin will likely display entries of changes made by normal users so you have to think about how you want the entries displayed
I have a website that is using Django's admin interface to facilitate non-developers adding content to the site. The site has an Events page (and associated model), and each Event can have an associated photo gallery.
I'm thinking that photo galleries should have their own model. There is a table in the database which associates image paths with their Event.
What I need is a way to upload images. Preferably a multiple-file upload solution since there could be dozens of images per event. I want these images to be recorded correctly in their table and added to the file system in the correct location on the server.
I was originally thinking that the upload feature should be included on the Event admin page to make it easier for content contributors, but maybe it would be easier to keep a separate photo gallery admin and have them select the Event the photos are associated with from there?
I've read through a lot of similar questions and blog posts, but nothing that seems to be quite exactly what I'm looking for. I'm currently attempting to adapt some of the information I've seen, but I'd really appreciate suggestions. Thanks for any help on this!
You can create Some model with foreign key to Event, and ManyToMany to your Images, as I understand your question.
At first upload necessary images to some Image model and than add them to Some model with some Event
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
When you create or modify an object instance in Django's admin, a changelog entry is created. This is really nice for fairly obvious reasons.
However my model's instances created by a normal user outside of the admin interface. No changelog is recorded to note its creation (not a huge issue) but I would like to track edits the user makes.
I also want to show the user this full log (user+admin edits) in the frontend so I need a way to pull the changelog out.
My question: how? Is there a one-line switch I can flick to enable full logging or do I have to dig in and do something on my user's edit form logic?
django-reversion is an app designed to help with that.