step3
1. adding user to the tweets
update your models.py bu adding user column as
from django.conf import settings
one user have many other things also but user will be the one
2. open shell and test for the filter
from tweets.models import Tweet
obj=Tweet.objects.filter(content="hello")
obj
(output:<QuerySet [<Tweet: Tweet object (71)>]>)i.e in 71st obj content is hello
bj=Tweet.objects.filter(user=1)
bj
it returns all objects that has 1st user
if you want to search the tweet object with username than
bj=Tweet.objects.filter(user__username="admin") [two __ are necessary ]
if you change user__username="admiN" i.e case Sensitive it wont give you any object since no any object is there with admiN
to make case insensitive
bj=Tweet.objects.filter(user__username__iexact="Admin") [use iexact with 2 __ in front]
basically to make case insensitive we use iexact
to search content hello by typing Hello
bj=Tweet.objects.filter(content__iexact="Hello")
if you want to add search bar to the admin section of that tweet and search admin name ant load tweet acc. to your search content than
upper logic comes to play
in admin.py
it is case insensitive : iexact no need to place or you can do experiment(not full and final conclusion)
if you want to render username or any content inside models to RHS of each object than you can use
list_display i.e
but attributes should be column name : for user--> user not user__username like previous search case
meaning of __str__
in nepali tyesaiko : in upper case scenario: display the list of its own user
if you want to render the name of model as its content name than you can use __str__ in models.py
Comments
Post a Comment