Answer the question
In order to leave comments, you need to log in
Dynamic filter on Django?
Good day.
I have a "main" model:
class MainProcedure(models.Model):
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
procedure_id = models.CharField(max_length=32)
method_type = models.CharField(max_length=100)
owner = models.CharField(max_length=255)
def __str__(self):
return f'<MainProcedure (id={self.id.hex})>'
@property
def specific_procedure(self):
return getattr(self, f'{self.method_type}_procedure')
class FooProcedure(AbstractProcedure):
main_procedure = models.OneToOneField(MainProcedure, on_delete=models.CASCADE, related_name='foo_procedure')
class Meta(AbstractProcedure.Meta):
abstract = False
title
specific procedure, then I need to do something like this:q = Q(foo_procedure__title__icontains='title') | Q(bar_procedure__title__icontains='title')
return qs.filter(q)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question