.filter .get django code example
Example 1: filter django or
from django.db.models import Q
query = Q(first_name='mark')
query.add(Q(email='[email protected]'), Q.OR)
query.add(Q(last_name='doe'), Q.AND)
queryset = User.objects.filter(query)
Example 2: objects.filter django
>>> Entry.objects.filter(blog_id=4)
Example 3: filter field set in django formds
class AgregarProducto(forms.ModelForm):
class Meta:
model = productos
def __init__(self, *args, **kwargs):
user = kwargs.pop('user')
super(AgregarProducto, self).__init__(*args, **kwargs)
self.fields['secciones'].queryset = secciones.objects.filter(user=user)