django queryset for many-to-many field

后端 未结 2 1621
余生分开走
余生分开走 2020-12-24 15:14

I have the following Django 1.2 models:

class Category(models.Model):
    name = models.CharField(max_length=255)

class Article(models.Model):
    title = m         


        
相关标签:
2条回答
  • 2020-12-24 15:34

    Try:

    preference = Preference.objects.get(**conditions)
    Article.objects.filter(categories__in = preference.categories.all())
    
    0 讨论(0)
  • 2020-12-24 15:39
    Article.objects.filter(categories__in=myPreferenceObject.categories.all())
    
    0 讨论(0)
提交回复
热议问题