I have a list of video games in my database. The user is suposed to choose their favorite games by selecting the checkbox of the wanted game.
So I have a form with the entiere list of these games. For now I use a For condition to display all the entries from my database/table.
But now I have a huge list of game that the user can choose, so I can't display everything.
Do you think It could be a good solution if I replace my system by placing a search bar which could dynamicly search and add a game.
Is there a right way to do this with Django ?
If not, could you give me the simpliest solution to solve my problem ?
Thank you.
Probably you should make use of both approaches: have a list of (ordered by) most played games which could contain a few tens of games (with the possibility to "view more" at the end of the list) for users who don't know yet what game to play and who like to discover new games. And also have a search box where users can enter the name of a game if they already know what they want to play and don't want to look it up in a list of games.
For the "view more" part of the list you should use ajax to make calls to django app without reloading the entire page and retrieve a number of games by each call. This will be more like a Single Page Application (like Twitter, for example).
Or you could use pagination and retrieve and display all games from the start and use a cache framework (and cache the query that retrieve all games) if there are performance issues.
Related
I am trying to make a simple e-commerce website and followed some tutorials.
However, the author of the book used complicated function based view to make cart function..
there are bunch of session stuffs.. and I don't understand the logic..
and I am trying to think the other way..
what about using database to store all the cart related data, and
use CBV to build it?
for example,
CartListView to see the contents of the cart, and CartUpdateView to change the quantity..
then are they going to be two different pages? separated page that user should go to the
different page to change the value??
please help me T T
You can access the session in any sort of CBV as self.request.session and a "shopping cart" is normally stored therein.
You'll certainly need to implement a CartListView to see what's in it, or possibly a CartEditView to show the cart with options to edit the quantities and delete anything that shouldn't be in there.
Adding products to the cart may well be an "Add" button on a ProductDetailView or lots of add buttons in a ProductListView. You might add a POST handler method to these views which are otherwise read-only (GET-only) bt default. Or you might make them FormViews, even though the form would be hidden and filled/POSTed by JS rather than the shopper doing anything other than clicking "add".
And then there will be a CheckoutView.
Check https://djangopackages.org/ (put "cart" in the search box). this will throw up several shopping cart things which might be the code you want, or the source of which might be a valuable learning resource before you end up rolling your own.
I am moving from Rails to Django and trying to convert a Hamper Business website I run. Love Django!!
I have hampers with a number of products. Each hamper has different products. I'd love to be able to use the following structure to move products into a hamper.
An example: Django uses the following to have a list of groups which then moves to Chosen Groups:
All I seem to be able to get with a ManyToManyField is a list box which I have to select by control and clicking to add multiple fields. This becomes impractical and not easy to read.
To take it one step further, I'd love to be able to include a product more than once. For example, a hamper which has three bottles of the same beer. I would like to not have to set up three seperate products for the same hamper.
Thanks so much in advance for pointing me in the right direction.
I found the answer for part of it. I simply added filter_horizontal to the admin.ModelAdmin class in admin.py.
Still not sure how to add multiple quantities, but I'll maybe save that for another day.
I have a Django project where I am pulling back a list of tasks. These tasks could be for many projects.
Task1: Project1
Task2: Project2
I really want to be able to group by project, so they all sit together, but the project names are input by the user, so I can't hardcode if statements.
How could I approach this?
You should not hardcode, period.
You really should work on your question skills. Based on the little information you gave, Your problem might be one of the following.
You need to search in your database based on the project name that the user has searched for. You have a few ways to approach this, based on your javascript abilities (in no particular order):
Give the user a list of cards, each of which represents a single project. Once the user clicks on the card, you get the project id, send it to the server and fetch it from the database. You might need to look into frameworks such as React, or Vue for this task even though you can achieve the same with vanilla JS.
Create a simple text field, take the user input, query the input against your database and return the list of results, or tell the user that there is no project by the given name.
Create an advanced text field where the list of projects are suggested based on the input of the user (somewhat like the Google search input)
Create a select dropdown, populated with the names of projects, and allow/force users to select one.
OR, you just need to show all of your tasks but just nest the tasks in their parent projects. The simplest way to achieve this is explained here. The other way (the better way) to approach this is to serialize the projects and add the corresponding array of serialized tasks.
how can i extract name list && phone numbers of the users liking certain page ?
I have tried using software called facepager but i couldn't extract names .
note:I'm not the owner of the page
You'd most likely have to write code yourself to do something like this. However,
Almost no-one publicly shares their phone number.
Facebook try to prevent this kind of data collection.
Even when facebook list's "likers" of a page, it'll wait till you scroll down to load more. You'd have to play with your browsers debug tools and look into where it get's that data from
https://www.facebook.com/search/<group id here>/likers
In the end you'll probably not get much better than just searching for the page and clicking each person's profile because the site is designed to not let what you're trying to do happen...
I am building a web app that allows our field staff to create appointments. This involves creating a record that contains many foreign keys, of which some come from very large tables. For example, the staff will need to select one of potentially thousands of customers.
What's the best way of doing this in Django?
A pop-up box that allows the users to search for customers, gives them the results, the user selects the results, then fills out the main appointment form and then
disappears?
Changing the appointments form to a customer selection page that
then reloads the appointments page with the data in a hidden form? Or
holding the data in some session variables?
Some from of Ajax approach.
A wizard where the flow is: a customer search page, a list of results and they select from results, then a search page for the next option (for example product selection), etc etc
(I'd like to keep it as simple as possible. This is my first Django
project and my first web project for more years than I care to
remember)
ALJ
Imho you should consider some kind of autocomplete fields. I think this results in the best usability for the user. Unfortunately, this always involves Ajax. But if you think that all users have JS turned on this is no problem.
E.g.
django-autocomplete
or what is probably more powerful:
django-ajax-selects
If you do the wizard approach, it will take longer for the user to accomplish the task and makes it harder to change selections.
Edit:
Well with django-ajax-selects you can define how the results should look like. So you can e.g. add the address behind the name.
Quote:
Custom search channels can be written when you need to do a more complex search, check the user's permissions, format the results differently or customize the sort order of the results.
I have done this before by integrating a jQuery autocomplete plugin. But, seeing as this is your first project and your desire to keep it simple, I suppose you could go with the session data option. For instance, you could show a search page where users could search for and select a customer. You could then store the, say, ID of the selected customer object as session data, and use it to pre-populate the corresponding field in the form when displaying the form. That's what I think offhand.