Kamarat AbdelSalam
Kamarat AbdelSalam

Reputation: 110

how filter posts for django-modeltranslation

I used Django ModelTranslation how can I get all post by language

model.py
class post(models.Model):
    title = models.CharField(max_length=255)
    text = models.TextField()

I want to get all posts en or ar language for ex.com/en or ex.com/ar

views.py
def home(request):

    all_posts = Post.objects.all( )

Upvotes: 0

Views: 85

Answers (2)

Ahmed Az
Ahmed Az

Reputation: 91

you want to change your code like this

from django.contrib.auth.models import User

def home(request): 
    all_posts = Post.objects.filter(author__in=User.objects.all() )

Upvotes: 0

Hady
Hady

Reputation: 21

you can filter posts with filter function like this :

qs = Post.objects.filter(title="hello world")

and My advice to you is to read QuerySetApi

Upvotes: 1

Related Questions