question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help creating preferences on the fly

See original GitHub issue

I am trying to create a queryset filter on the fly per model and per user.

All my ListViews inherit from a class that has a filters(self) property. In that section I want to create a preference for queryset filters using django-filter module.

I have found several issues with my approach:

def filters(self):
            self.filter_name = self.model.__name__ + "FilterSet"
            self.filter_preference_name = "%s_%s_filter" % (self.model._meta.app_label, self.filter_name.lower())
            self.filter_preference_full_name = "Personal__%s_%s_filter" % (self.model._meta.app_label, self.filter_name.lower())
            self.filter_preference_class_name = "FilterPreference%s%s" % (self.model._meta.app_label.title(), self.filter_name)
            if self.filter_preference_full_name not in preferences_manager.keys():
                FilterPref = type(str(self.filter_preference_class_name), (StringPreference,), {
                'section':personal,
                'name':self.filter_preference_name,
                'default': '{}',
                'instance': self.request.user,
                 })
                user_preferences_registry.register(FilterPref)

Some times preference is created but not persistent. When I change from /myob/list to /anotherobj/list myobj list disappears. Some times preference is not created at first time, and is created after a second reload.

I also have tried creating preference using orm like in tests and does not persist: UserPreferenceModel.objects.get_or_create( instance=self.henri, section="misc", name='is_zombie')[0].value)

I would not like to create a dynamic_preferences_registry files and objects for more than 30 models, plus I am planning to set settings also for tables: per_page and list_mode (table, cards, …)

Any ideas why my approach is wrong? is it possible?

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
n3stormcommented, May 15, 2017

I proceed to close the issue. Thank you so much, Eliot!

1reaction
agatebluecommented, May 9, 2017

But I suspect your problem here is that you try to register preferences dynamically after your server started. This is maybe possible, but not explicitely supported by this project: you have to declare preferences statically (you can use inheritance and mixins, though) so they are picked up and loaded during the apps loading.

You can do that, and still use that dynamical approach of yours to filter preferences in a view, though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

estimating preferences on the fly with Enginius - YouTube
Conjoint analysis is one of the most widely used technique in marketing research. It helps understand (and, more importantly, ...
Read more >
Set up preferences - Help Center - WordFly
1. Go to Subscribers > Preferences · 2. Click the Create button. If the button is greyed out, make sure you have the...
Read more >
How to change Simulink preferences on the fly? - MathWorks
I tried opening the model and using set_param(ModelName,'AutoSaveOptions',0). But it does not work (as there is no 'AutoSaveOptions' parameter). Any help ...
Read more >
Female toads avoid hybridizing by switching mate preference ...
When looking for mates, female Mexican spadefoot toads have a dilemma: Males with faster mating calls are more likely to produce fitter ...
Read more >
Signing-on-the-Fly: Technology Preferences to Reduce ...
Signing-on-the-Fly: Technology Preferences to Reduce Communication ... technologies that support hearing parents to deliver ASL on-the-fly, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found