36๐
โ
A more direct alternative:
autors = Autor.objects.filter(recolha__categoria=MyCategoria)
where MyCategoria
is the relevant CategoriaRecolha
instance. Or, if you want to match agains the specific category name, you can extend the query another level:
autors = Autor.objects.filter(recolha__categoria__categoria='my_category_name')
๐คDaniel Roseman
23๐
in django 2 is ForeignKey.limit_choices_to docs
staff_member = models.ForeignKey(
User,
on_delete=models.CASCADE,
limit_choices_to={'is_staff': True},
)
๐คsVs
- [Django]-Django: Make certain fields in a ModelForm required=False
- [Django]-How to dynamically compose an OR query filter in Django?
- [Django]-How to have a Python script for a Django app that accesses models without using the manage.py shell?
5๐
cat = CategoriaRecolha.objects.get(field=value)
rows = Recolha.filter(categoria=cat)
autors = [row.autor for row in rows]
The Django Docs explain this pretty well.
๐คunderbar
- [Django]-Display django-pandas dataframe in a django template
- [Django]-AttributeError: 'ManyRelatedManager' object has no attribute 'add'? I do like in django website but got this error
- [Django]-How to get OR permissions instead of AND in REST framework
Source:stackexchange.com