Comments (4)
@kennylajara as explained in #242, it should be relatively easy to achieve this by:
- extending
ThemeQuerySet
- overriding
get_active
method (here you decide the theme to return) - setting the customized queryset as default objects manager for the
Theme
model.
If you will come back with a reusable solution I will be glad to look at it!
from django-admin-interface.
I can think on using something like this to determine if the Site framework is being used:
from django.conf import settings
def is_sites_app_installed():
if 'django.contrib.sites' in settings.INSTALLED_APPS:
try:
from django.contrib.sites.models import Site
return True
except ImportError:
return False
return False
Extend the Theme
model to add this property:
site = models.PositiveSmallIntegerField( # it can be a FK too
blank=True,
default=1,
verbose_name=_("site"),
)
And change the QuerySet to this:
class ThemeQuerySet(models.QuerySet):
def get_active(self):
using_sites_framework = is_sites_app_installed()
if using_sites_framework:
objs_active_qs = self.filter(active=True, site=Site.objects.get_current().id) # `Site.objects.get_current()` is `site` is a FK
else:
objs_active_qs = self.filter(active=True)
objs_active_ls = list(objs_active_qs)
objs_active_count = len(objs_active_ls)
if objs_active_count == 0:
obj = self.all().first()
if obj:
obj.set_active()
else:
obj = self.create()
elif objs_active_count == 1:
obj = objs_active_ls[0]
elif objs_active_count > 1:
obj = objs_active_ls[-1]
obj.set_active()
return obj
But I think it will still require a way to handle sites that are added and have not set any Theme yet. It might be a way to mark a theme as default or something else.
from django-admin-interface.
Would that work for you? I really need this feature, so, I'm willing to develop it with you guidance.
from django-admin-interface.
@kennylajara it's hard to give help based on code snippets pasted here, I would suggest you to work on your own solution that works well for your use case and that is enough generic to fit other people needs, then submit a PR.
from django-admin-interface.
Related Issues (20)
- Filter Input Fields collapsing on different layouts HOT 1
- Adding Support for `django-rosetta` Package HOT 1
- TemplateDoesNotExist with use django-nested-admin HOT 2
- Bug in display of related links with autocomplete fields HOT 5
- django.db.utils.ProgrammingError: relation "admin_interface_theme" does not exist HOT 2
- Unnecessary warning for missing django.middleware.locale.LocaleMiddleware if using customized middleware HOT 4
- Enable possibility to use a static file as logo HOT 18
- Object of type Theme is not JSON serializable HOT 20
- The default View Site link not showing in the mobile version HOT 1
- Popup window freezes in Chrome after save HOT 4
- Django admin date_hierarchy linking is not working anymore HOT 6
- Related modal window includes the header. HOT 4
- Serving static files with Amazon S3 and signed querystring problem
- missing check for show_inlines_as_tabs in template HOT 2
- [css] m2m selector not styled correctly.
- Maintain Active Tab After Clicking "Save and continue editing" HOT 1
- Partial facet support HOT 1
- Support for Django 5.1 HOT 5
- Django Style override the Selected Style HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-admin-interface.