Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I practice coding with html and django and I have a project "Movie Reviews" and I have some question.
how to show category for user who often click that category?
e.g
You often like to chose Romantic category.Website should show romantic category to you when you come to this website again.(already login)
sorry for my English.I'm beginner for English and Coding.
Thankyou
This question is very wide, but this should help you; I guess you already have a Category and a Movie model, right?
Those two are probably related trough a one-to-many relationship. Here you should do something similar, but you'll need a many-to-many relationship.
The simplest way of doing it would be to create a new model, for example 'CategoryVisited', with 3 fields: user_id, category_id, and count.
Then, each time a user visits a category, you'll either create a new CategoryVisited or get the existing one matching the current user_id and category_id, and increment the 'count' field.
At last, to retrieve the preferred category of a user, you'll have to write a simple 'max' request to get the category_id with the max count for the current user.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need something to view the queries happened ( creating or updating or deleting ) in DB tables in Django, I want it to be able to be used by the user, not at the admin panel
If I understand your question correctly, you are looking for a model history (sometimes also called "audit trail").
In this link there is a comparisson of different packages that can be used for audit/history of models.
As I already pointed out in this answer,
I use django-simple-history which comes with a nice integration to view the list of changes of every model instance in the admin.
For my use case at least, django-simple-history provided me with what I needed, and so far I did not face any issues with it, even though this package does NOT track history of ManyToManyField (for that see related questions like this or this or the Github issue).
Now, if you want the end user to be able to see the history (but not through the admin panel), then you would need to add a few pages for that.
For example, you could add a list view for each model using djangos generic ListView.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How do I create a new model for every user in django. Like a new list of items for every new user
That is not something you should do.
A model is the single, definitive source of information about your
data.
This implies that the model can't be different for every single entity (the user in this case) in your app. A definitive source for your data should not have to be unique for every user.
For more on Django models: https://docs.djangoproject.com/en/1.10/topics/db/models/
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm looking to create a one-to-one relationship between two types of Django users. I want one user to initiate a request for relationship creation and I want to create it only if the second user agrees to it.
Is there a good way to remember the request to create the relationship but only actually create it once the second user agrees to it with Django?
Something like
class Relationship(models.Model):
invite_user = models.OneToOneField(
User,
on_delete=models.CASCADE
)
accept_user = models.OneToOneField(
User,
on_delete=models.CASCADE
)
accepted = models.BooleanField(default=False)
Then when a user send request for relationship, just create a record Relationship with accepted=false then if user accept, change to accepted=true. You can also add created_at, accepted_at also.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Hi my project works on Django Python. What I want to achieve is since django tasty pie doesn't support combining two resources(no relationship b/w the tables), I need to come up with my own resource. Here I have 2 tables, Table A and B. There is no relationship b/w these 2 tables. But both the tables have a field/column named gname in common. So I want to get all the distinct gnames from both the tables and put it into one list (no duplicated values) and I need to display these gnames as a list in my template. Is there anyway to do that? Thanks in advance.
try:
gnames1 = list(A.objects.values_list('gname',flat=True).distinct())
gnames2 = list(B.objects.values_list('gname',flat=True).distinct())
gnames = list(set(gnames1+gnames2))
render(request, 'sampletemplate.html', {'gnames':gnames})
Set is a data structure that doesn't allow duplicate values.
You can add all the values from both the tables to it and I think you are good to go.
Python Sets
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm just wondering if there's a simple enough way to iterate over all comments made by a particular user (I want to check for a particular phrase).
Any help is appreciated :)
You can't get all comments, if the user has more than 1,000 comments. It is a limitation of the reddit API. However, the code below will get (and print the body) of all comments made by a user.
import praw
r = praw.Reddit('Your unique user agent')
user = r.get_redditor('REDDITOR-USER-HANDLE')
for comment in user.get_comments(limit=None):
print comment.body
A coupe notes:
Remember to have a unique user agent
REDDITOR-USER-HANDLE is the user name of the user you are looking at