I have a page where I'm displaying the title of something. Users are allowed to provide their own suggested titles. The title I originally display is stored under the event's object. All suggestions are stored in their own table. Each suggestion has a vote count associated with it. I want to display the original title unless there is a suggestion that is above some threshold of votes, but if several are above that threshold, I want to display the highest one. How would I grab the highest-voted suggestion from the list, but only if it is above some arbitrary threshold, let's say 5?
Add an integer field for the number of suggestions for a suggestion model.
Then find the highest suggestion and check if it has more than 5 votes
Related
I want to make a site where people can make listings for things to sell. I want it to have a front page where the most popular (hot) items are always displayed.
Popularity decreases with time and increases with activity (bidding, commenting, clicking). Every item starts with a popularity of 100.
That way uninteresting items dissapear quickly and interesting ones stay on longer.
So everytime a user interacts with the objects its popularity should increase (for example, everytime a get request from a unique user is made for the details of the object, its popularity value goes up by 1, every bid increases it by 10).
On the opposite, everytime a minute or so passes, the popularity of all currently active items decreases. Once it hits 0, it will be "deactivated" it will still be tradable, but it will never hit the frontpage again.
The problem is, how do I decrease the popularity of a queryset of all active items?
I realize that everytime the user request the front page. I could just fetch all active objects, calculate the popularity within python code and sort them by hand, but that seams rather wastefull.
I know I can easily set a property of an entire queryset, by using the update function, but that only takes one absolute value for the entire set. Is there a built in way to just decrease the property by one?
Or do I just have to loop through the queryset and decrease every value manually?
class Item(models.Model):
popularity = models.IntegerField()
Item.objects.update(popularity=models.F('popularity')-1)
This is how you update a queryset based on the values it has instead of giving it an absolute value, you can tweak this around to fit your needs.
Well, this might be a bit odd, but I was wondering if it is possible to make a search based on the label for choiceFields rather than the stored database value.
I have an app that when the user searches for a vehicle of type truck, the query can't retrieve results because the value stored in the database is tru, although choiceField label is truck. The same goes for gender female is fem, for example.
I could go around this problem with alternative ways, but I was wondering if Django had this implemented somehow.
I think you should consider changing the search functionality to search with the shortened name. You can still display the label on the front-end: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#Examples
We do not want to limit the number of items a person orders. Our products are all priced the same based on size. The only way I have found to do this with Opencart is by giving them an item a price of zero and controlling the price by using options.
Our problem is a user can not purchase more than one of an item. This may or may not be related to the option condition mentioned above.
EXAMPLE: Say the product is a t-shirt and we want the size to be an option. The customer would choose a design then a size. Then quantity and checkout.
Model number is the design.
The price is based upon size.
PROBLEM: Customer is limited to one t-shirt per model. In order words they can not order two size smalls of the same design.
Your problem does have a solution. You can order more than 1 size of the same design. I see that your problem is when you add the item on your shopping bag. When you go to checkout/cart page, there is a quantity column where in you can modify the quantity of your order.
For one of our clients, I manage a Magento store. The problem with this one is that, even though I have selected an attribute to sort on, the order of the products in the category list view is randomized within values.
Maybe this will make it a bit clearer:
Say I have sorted the category by the "bla" attribute.
Say 30 products have value "aa" on the "bla" attribute and 30 other products have value "ab".
Then Magento will first show all products that have value "aa" on the "bla" attribute and then the 30 products that have value "ab" on the "bla" attribute.
So far so good. However, within the "aa" products, the order keeps changing randomly. Even when still browsing the same category. Since there are sometimes 100+ products that have the same value on the "bla" attribute, this can lead to some product being displayed on the first page of the category list view, but then we encounter it again on the 3rd or even 4th page. Of course, Magento should remember the order in which the products are displayed to ensure that page navigation can never throw duplicate products at me, right?
So.. What's happening? Is this standard Magento behavior?
More importantly: what can I do about it?
Searching Google, Stack Overflow, etc. did not help me at all, so that's why I'm asking.
You can set position for each product in category and when you open category page - products will be ordered by it:
Is it what you are looking for?
I'm looking for an algorithm to determine ratings or tags for items when my own input is giving the user random sets of these items and letting them tell me which ratings or tags are within that set. For example, they might say if a set of images contains any "good" photos and out of several random sets and I then want to determine which photos are good. Now, I also can adjust the sets of items I give the user to those that would help me refine the knowledge of these items. So, if a given item was in sets marked both "good" and "bad", the system would try to place it in sets of known good items, perhaps, to determine if the user now says that set has a bad item, and I know the one with unsure status is the "bad" item. Does this make sense?
Use an artificial neural network; see Wikipedia. There are lots of links at this FAQ.