MrName
MrName

Reputation: 2529

Django - User Defined Queryset Filtering

I am working on an application where end users need to be able to define queryset filters through an interface. These filters are used to select instances of a model to ship off to another web service at timed intervals. Contrived example:

class Thing(models.Model):
    stuff = models.CharField()

I need users to be able to configure a timed task where only Things with a value of test for the stuff field will be selected.

I currently have a working POC for this functionality, but it involves a lot of hand coded logic.

Given that django has such a rich community and ecosystem, I was wondering if I am missing an opportunity to do this in a simpler way.

Looking forward to your feedback!

Upvotes: 1

Views: 247

Answers (1)

wiesion
wiesion

Reputation: 2445

If i understand your requirements correctly:

  • A user must be able to configure a filter which specifies which Things should be selected - without any programming knowledge, just through a GUI
  • A user must be able to set up timed tasks and specify which web service is targeted and which filter should be used to send the appropriate data

Based on this premises, i would:

  • Use https://github.com/modlinltd/django-advanced-filters
  • Create a Model/Form/View for TimedTasks which contain the relation to AdvancedFilter and the webservice specs
  • Retrieve the data through AdvancedFilter#query in the task runner, set up and call the webservice

This way the user can use the Overview page of Thing to create his data filters, and can link them in the creation of TimedTask along with the webservice config.

Upvotes: 2

Related Questions