Mohsen Tamiz
2018-05-05 12:44:26 UTC
I asked this question <https://stackoverflow.com/q/50001616/2335245> in
stackoverflow few days ago, but currently I could not find the solution for
my problem.
I have 3 different classes
#models.py
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
class PersonSession(models.Model):
start_time = models.DateTimeField(auto_now_add=True)
end_time = models.DateTimeField(null=True,
blank=True)
person = models.ForeignKey(Person, related_name='sessions')
class Billing(models.Model):
DEBT = 'DE'
BALANCED = 'BA'
CREDIT = 'CR'
session = models.OneToOneField(PersonSession,
blank=False,
null=False,
related_name='billing')
STATUS = ((BALANCED, 'Balanced'),
(DEBT, 'Debt'),
(CREDIT, 'Credit'))
status = models.CharField(max_length=2,
choices=STATUS,
blank=False,
default=BALANCED
)
#views.py
class PersonFilter(django_filters.FilterSet):
start_time =
django_filters.DateFromToRangeFilter(name='sessions__start_time',
distinct=True)
billing_status =
django_filters.ChoiceFilter(name='sessions__billing__status',
choices=Billing.STATUS,
distinct=True)
class Meta:
model = Person
fields = ('first_name', 'last_name')
class PersonList(generics.ListCreateAPIView):
queryset = Person.objects.all()
serializer_class = PersonSerializer
filter_backends =
(django_filters.rest_framework.DjangoFilterBackend)
filter_class = PersonFilter
Using this models and views I assume that url like this:
api/persons?start_time_0=2018-03-20&start_time_1=2018-03-23&billing_status=DE
must give me all persons that has session started between two times also
they have DE status, but what I give is all persons that has at least one
DE billing status independent from its start_time and persons that have
start_time between time defined independent from its billing status, In
other words I assume that the conditions would be applied as AND condition
but it seems that they apply like OR condition. In the question in
stackoverflow I have writtern an example to show my problem more clear.
How could I get the correct answer as I expected?
stackoverflow few days ago, but currently I could not find the solution for
my problem.
I have 3 different classes
#models.py
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
class PersonSession(models.Model):
start_time = models.DateTimeField(auto_now_add=True)
end_time = models.DateTimeField(null=True,
blank=True)
person = models.ForeignKey(Person, related_name='sessions')
class Billing(models.Model):
DEBT = 'DE'
BALANCED = 'BA'
CREDIT = 'CR'
session = models.OneToOneField(PersonSession,
blank=False,
null=False,
related_name='billing')
STATUS = ((BALANCED, 'Balanced'),
(DEBT, 'Debt'),
(CREDIT, 'Credit'))
status = models.CharField(max_length=2,
choices=STATUS,
blank=False,
default=BALANCED
)
#views.py
class PersonFilter(django_filters.FilterSet):
start_time =
django_filters.DateFromToRangeFilter(name='sessions__start_time',
distinct=True)
billing_status =
django_filters.ChoiceFilter(name='sessions__billing__status',
choices=Billing.STATUS,
distinct=True)
class Meta:
model = Person
fields = ('first_name', 'last_name')
class PersonList(generics.ListCreateAPIView):
queryset = Person.objects.all()
serializer_class = PersonSerializer
filter_backends =
(django_filters.rest_framework.DjangoFilterBackend)
filter_class = PersonFilter
Using this models and views I assume that url like this:
api/persons?start_time_0=2018-03-20&start_time_1=2018-03-23&billing_status=DE
must give me all persons that has session started between two times also
they have DE status, but what I give is all persons that has at least one
DE billing status independent from its start_time and persons that have
start_time between time defined independent from its billing status, In
other words I assume that the conditions would be applied as AND condition
but it seems that they apply like OR condition. In the question in
stackoverflow I have writtern an example to show my problem more clear.
How could I get the correct answer as I expected?
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.