darklow / django-suit

Modern theme for Django admin interface
http://djangosuit.com/
Other
2.31k stars 700 forks source link

Django Suit version 2.0 #475

Open darklow opened 8 years ago

darklow commented 8 years ago

Brace yourselves, this is going to be a long post!

I have bad news and good news. The bad news is - Bootstrap 3 branch will be discontinued. The good news is what is coming instead! 

Some history

Some time after i launched the very first Django Suit (DS) version I realised biggest challenge is to keep up with Django admin changes. And bs3 branch version proved that even more. I haven’t finished it yet as Django admin started changing quite a lot. New templates, new features, new styles etc. Third party apps are also changing and evolving a lot, therefore same problem existed with 3rd party apps too. I knew i needed to solve this issue before continuing.

Flexbox

Recently I did a lot of thinking and experimenting and because browsers have evolved significantly I found an answer to my problems - Flexbox. I’ve been working on Django Suit fresh rewrite for few weeks and haven’t overridden a single Django admin template and in the end of the post you can see real screenshot of what i achieved by CSS only.

So this is a short story how Django Suit v2.0 rewrite started.

I will try to avoid any Django admin templates override as long as possible and if needed i will use JS DOM manipulations instead of overriding templates, which gives a few huge benefits: When Django admin templates changes, some minor visual bugs may appear, but it will not break anything.

Without overriding admin templates, we have much wider 3rd party app support. Any app that haven’t modified templates too much and use Django admin markup should work perfectly. This gives us much wider Django version support range, however I think Django Suit will stay with 2-3 recent version support.

What’s new in Django Suit v2

So here is the current state of v2.0 rewrite. No templates overridden except base_site.html:

image

Todo:

If you're ok with incomplete features and missing documentation (demo app with all examples is included) then feel free to install or even use it for production (I personally use it in production for a few projects already):

pip install https://github.com/darklow/django-suit/tarball/v2

In requirements.txt:

 -e git://github.com/darklow/django-suit.git@v2#egg=django-suit

Work in progress links: v2 demo: http://v2.djangosuit.com/admin/ v2 branch: https://github.com/darklow/django-suit/tree/v2 v2 docs: http://django-suit.readthedocs.org/en/v2/

Feel free to share your thoughts.

gamesbook commented 7 years ago

@darklow At this rate (no official release of v2 as yet), we can delay upgrading until April 2017, which is when Django 1.11LTS comes out. Can I assume Suit will be supported in that release?

darklow commented 7 years ago

@gamesbook I was thinking more of - are you really considering moving your existing clients who uses Django 1.8 to suit v2 as v1 and v2 are not exactly compatible, some config and other changes will be required. So maybe my work for 1.8 is really redundant.

I will try my best to release v2 this year. Instead, today I spent 4 hours just trying to deal with Django 1.8 compatibility and still haven't found good solution that nicely would work for 1.8 and 1.9/1.10. I really don't want to use some custom extends template tag for all suit templates to fix circular imports for Django 1.8.

Django 1.11 will be supported and for future I was thinking of keeping up supporting 3 versions of Django with one version of suit.

kcolton commented 7 years ago

@gamesbook This is going to come across rude, but it comes entirely from my own history of mistakes (as i've gotten stuck in dependency hell and fallen behind on being able to upgrade important frameworks and know its also often completely out of ones control).

Without knowing anything about your situation, FWIW if you are stuck on 1.8, Django Admin being BS4 should probably not be high on the priority list. If you need Bootstrap, I would actually recommend the no longer maintained BS3 branch of suit. We used it in production for quite a while and it worked basically fine.

IMNHO I think BS4 itself is suffering from it's own "backwards compatability" issues. By the time they get to an RC, flexbox will be so universally supported it wont matter that it has table support.

BS3 was a big step forward in that it just said screw it, * { box-sizing: content-box; } and any of the poor souls who needed to support older IE was "stuck" with a still perfectly usable BS2.

1.8 is was labeled LTS, and they have a duty to support that, but third party packages don't have the same support ecosystem and you can always pin older versions of packages.

Unfortunately, pip is not so magical to work the other way around, otherwise @darklow could just pip install django-suit==2.0.0 and there would be no problem. 😆

heathernicoale commented 7 years ago

@darklow - thanks! Great idea! :) I had just been reading up on print styles last week. The only reason I had been looking into print options (or actions for that matter) was because we have so many rows of data. We can set up filters, but it still exceeds the visible print view and the pagination is also playing a factor in that as well. I was trying to add a print action / function to print ALL the rows in a dataset (even if it's not all visible in the browser window) -based on the filters or ordering set. Of course there may be another way to do this - I'm still a bit of a rookie. Thanks!

gamesbook commented 7 years ago

Our plan was to upgrade to 1.8LTS, but we need to keep using Django Suit (everyone we show it to reacts very well to the "look and feel") so I was waiting for v2 to support it before running any upgrades. A DSv2/ Django1.11(LTS) is just as valid from our point of view. The only issues might be - as @kcolton points out - other third party packages; but I am hoping they will also move to support 1.11, otherwise we will be forced to use a 1.9 or 1.10 in the interim.

I'd rather vote for an earlier release of v2 without 1.8 support than see it delayed (assuming my vote counts for anything).

chris-erickson commented 7 years ago

We have a lot of 1.8 LTS sites (and will until 1.11) so I would love to see 1.8 well supported. That said, I can appreciate the difficulty doing so, and desire to get better prepared for the next LTS first. We're I to vote, it would probably be to defer 1.8 support, so that the community as a while is better served - v1 works just fine for now.

darklow commented 7 years ago

@gamesbook @chris-erickson @kcolton Thank you for your feedback on Django 1.8. Since it was broke and I wasn't able to fix it, I am removing partial Django 1.8 support for now and will try one more time when v2 is finished.

darklow commented 7 years ago

Current login form seemed little too geeky and was bothering me for a long time. Because first impression is important and login form is the first thing that your (and my) clients see, I did some work on it. Live demo: http://v2.djangosuit.com/admin/ PS. Graphic is included only on demo, by default there is none. Example how to add one is here: https://github.com/darklow/django-suit/blob/v2/demo/demo/templates/admin/login.html#L4 image vs old: image

SalahAdDin commented 7 years ago

New login is better.

darklow commented 7 years ago

@gamesbook @kcolton and others. What are 3rd party packages you definitely require to work with Django Suit v2?

I would like to test them out first, how well they work out of the box, before releasing first v2 alpha. My intention from the very beginning was override as less templates as possible and use CSS/JS as first solution. This approach should allow other 3rd party packages to be supported without extra packages or too much work.

gamesbook commented 7 years ago

@darklow

My list (by the INSTALLED_APPS name and project URL):

Plus https://github.com/django-debug-toolbar/django-debug-toolbar is used for development.

raratiru commented 7 years ago

Thank you for this great effort.

I would like to mention an old issue ( https://github.com/darklow/django-suit/issues/367 ) regarding HiddenInput widget just to make sure that it will be fixed.

A very useful app, that I hope it will succeed in staying current and up-to-date, is django-leaflet.

hebijiandai commented 7 years ago

Excellent!

darklow commented 7 years ago

If you are using v2 and suit_row_attributes() be aware of backwards incompatible change: https://github.com/darklow/django-suit/commit/ea9731b43a65d7f3eef7abb19d971e594be3b4d5

request is now always passed to suit_row_attributes(self, obj, request) as second argument. Previously to keep BC in v1 argspec was used to determine if request is defined in args. Time to drop that in v2.

class MyAdmin(ModelAdmin):
    # ...
    def suit_row_attributes(self, obj, request):
        return {'class': 'type-%s' % obj.type}
a-trost commented 7 years ago

Been loving this update. Is there a way to change the "Suit Admin" header at the top left to an image instead?

darklow commented 7 years ago

@a-trost Sure, extend or replace {% block branding %} in your base_site.html file. https://github.com/darklow/django-suit/blob/v2/suit/templates/admin/base.html#L15

ghost commented 7 years ago

I've been experimenting with this beautiful admin (v2), and am considering using in production (the tab functionality alone would be a huge improvement for us!). I'm wondering whether you have any more info on a few things:

If horizontal list_filter and show_change_link are needed, are you recommending people stick with v1 for now? Thanks!

darklow commented 7 years ago

@jon1924

  1. Horizontal list filters are definitely next on the todo list. I would say maximum in a week.
  2. show_change_link is now natively supported by Django admin and also supported by Django Suit. See example here, you'll notice Change link: http://v2.djangosuit.com/admin/demo/continent/9/change/ I will need to do more research about django-controlcenter and pypi release. For new projects or the ones under development I suggest using v2, for existing ones stick with v1 until all features are migrated.
gamesbook commented 7 years ago

Assuming you have jumped through the hoops to add packaging info to your project, then this is a good way to test PyPI: https://wiki.python.org/moin/TestPyPI

darklow commented 7 years ago

Oh, you meant deploying v2 on pypi, yes of course I'll do that, although I wanted to do that only when the new docs are online, to avoid confusion. I bet lot of users will blindly run update and wonder what happened.

Right now I am deploying my Docker apps following way:

# requirements.txt
Django==1.10.5
# Django suit invalidate: 1
 -e git://github.com/darklow/django-suit.git@v2#egg=django-suit

And when I need to upgrade Django Suit I just change invalidate number. I know this is not perfect, but works as a workaround until pypi is online.

ghost commented 7 years ago

Thanks for the fast reponse. That's good news re: list_filter and show_change_link (I must be overriding something with the latter).

Docker pulls in django-suit v2 fine - it's just that the container rebuilds every time there's a repo change, unless you tie it to a particular commit. A stable PyPI release version would just let the container stay calmer. I'll try your invalidate method - that's a bit more convenient.

Getting excited about using this!

willseward commented 7 years ago

@jon1924 Strange that the docker container rebuilds when there is an upstream change to the git repo. It should only be looking at the local filesystem when deciding to invalidate the cache.

Have you tried something like this?:

COPY ./requirements.txt /src
RUN pip install -r /src/requirements.txt
COPY ./ /src

This will ensure that you can maintain a cached layer for the python installation and then modify your source code without invalidating the pip install. @darklow's invalidation solution is a good workaround until a pypi version is released.

darklow commented 7 years ago

@gamesbook @jon1924 @Sovetnikov Great news – horizontal list filters are ready! Even better - in classic v1 all filters where converted into horizontal, but now in v2 you can have both django original vertical filters and horizontal filters together. All you need to do is besides list_filter define also suit_list_filter_horizontal list for the vertical ones.

Live demo: http://v2.djangosuit.com/admin/demo/country/ Code example: https://github.com/darklow/django-suit/blob/v2/demo/demo/admin.py#L71

image

darklow commented 7 years ago

In v2 instead of adding support for 3rd party packages I will include examples of usages, widgets etc in the demo app instead, so they can be used as an example to copy into your app when needed. The pros are that it won't break your app if you upgrade Django Suit or update 3rd party app and you get some version mismatch, in such case you can easily adapt widget and maintain code for you needs.

Because https://github.com/applegrew/django-select2 is one of the most popular packages, I added example of how to use Django-Select2 Model widget in v2-dev.

Demo: http://v2.djangosuit.com/admin/demo/showcase/1/change/ (Under Foreign key relations) Code: https://github.com/darklow/django-suit/blob/v2/demo/demo/widgets.py#L6 https://github.com/darklow/django-suit/blob/v2/demo/demo/admin.py#L208

image

Related issues on Django-Select2 repo: https://github.com/applegrew/django-select2/issues/279 https://github.com/applegrew/django-select2/issues/284

I think I am ready to start writing new documentation for v2 now and then 🎉

gamesbook commented 7 years ago

@darklow "The cons are that it won't break your app" - you mean, "The pros are that it won't break your app"?

Great news on horizontal filters - they are a must when the lists get too long!

On 11 February 2017 at 23:10, Kaspars Sprogis notifications@github.com wrote:

In v2 instead of adding support for 3rd party packages I will include examples of usages, widgets etc in the demo app instead, so they can be used as an example to copy into your app when needed. The cons are that it won't break your app if you upgrade Django Suit or update 3rd party app and you get some version mismatch, in such case you can easily adapt widget and maintain code for you needs.

Because https://github.com/applegrew/django-select2 is one of the most popular packages, I added example of how to use Django-Select2 Model widget in v2-dev.

Demo: http://v2.djangosuit.com/admin/demo/showcase/1/change/ (Under Foreign key relations) Code: https://github.com/darklow/django-suit/blob/v2/demo/demo/ widgets.py#L6 https://github.com/darklow/django-suit/blob/v2/demo/demo/admin.py#L208

Related issues on Django-Select2 repo: applegrew/django-select2#279 https://github.com/applegrew/django-select2/issues/279 applegrew/django-select2#284 https://github.com/applegrew/django-select2/issues/284

I think I am ready to start writing new documentation for v2 now and then 🎉

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/darklow/django-suit/issues/475#issuecomment-279175960, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVm67CpcJ-wwTgZugZbUZr2EDpYaiFcks5rbiOvgaJpZM4HP7vt .

darklow commented 7 years ago

@gamesbook yes I meant pros :) thanks

luison commented 7 years ago

Just to inform that V2 demo seems to be down. Happy to see v2 is being pushed but just trying to see what is the current situation with v 1.9 support. I've read that 1.8 support is not 100% and seen a requirements.txt with 1.10. Is that going to be the minimum supported version initially? Thanks.

gamesbook commented 7 years ago

Given that Django 1.9 extended support stops in 2 months time, it does not seem to make sense to try & support it (for a small project like this).

(And yes, http://v2.djangosuit.com/ returns a 502)

darklow commented 7 years ago

@luison and @gamesbook Thanks for letting know v2 demo is down, wasn't aware of that. Now it is back again, was playing with docker and accidentally mess it up a little.

Currently Django Suit supports perfectly both Django 1.9 and Django 1.10, until it doesn't make hard to maintain, can't see why to drop support for Django 1.9 either. @luison requirements.txt is just for the demo. Also non of my current projects had any problems moving from 1.9 to 1.10, so I would say by my experience they are very compatible.

I am starting to doubt about wether to support Django 1.8, because of it's older template loader system, which makes it really hard extend in a clean way and avoid circular imports, also Django 1.11 is not so far away, so maybe I should look forward, not backwards.

luison commented 7 years ago

Thanks for the quick and detailed reply. We´ll go ahead and try it on a project running on 1.9

On 13 February 2017 at 22:25, Kaspars Sprogis notifications@github.com wrote:

@luison https://github.com/luison and @gamesbook https://github.com/gamesbook Thanks for letting know v2 demo is down, wasn't aware of that. Now it is back again, was playing with docker and accidentally mess it up a little. Currently Django Suit supports perfectly both Django 1.9 and Django 1.10, until it doesn't make hard to maintain, can't see why to drop support for Django 1.9 either. @luison https://github.com/luison requirements.txt is just for the demo. Also non of my current projects had any problems moving from 1.9 to 1.10, so I would say by my experience they are very compatible.

I am starting to doubt about wether to support Django 1.8, because of it's older template loader system, which makes it really hard extend in a clean way and avoid circular imports, also Django 1.11 is not so far away, so maybe I should look forward, not backwards.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/darklow/django-suit/issues/475#issuecomment-279527186, or mute the thread https://github.com/notifications/unsubscribe-auth/AAtgoIdfPgGx3jhb2DXgAb2Yx60SPVJzks5rcMo3gaJpZM4HP7vt .

metaabc commented 7 years ago

If I use the static external URL in the menu, how to format the URL base on the request user language?

ChildItem('web site', url='http://test.site/{}/index.html'.format(language_code))

Thanks!

gamesbook commented 7 years ago

I cant speak for anyone else, but v.10 and v.11(LTS) support would be more than adequate. v.11alpha is out now, so I assume preliminary tests could be run on that prior to its April release?

darklow commented 7 years ago

@fastdevops url can be callable too. request and context variables will be passed: https://github.com/darklow/django-suit/blob/v2/suit/menu.py#L217 PS. Please open separate issue if you want to discuss the issue more

alexphelps commented 7 years ago

@darklow Firstly, I want to say that v2 is awesome. I just getting started with it on a new project.

I would like to know how to move the Change Form Submit buttons down to the bottom like standard django for wider forms. I have quite large codemirror textarea form widgets and on a small screen with the navigation on the and submit row on the right which results in a slim middle column for the form.

Would this be possible or possibly a setting to be able to toggle the change submit buttons location?

darklow commented 7 years ago

@alexphelps Thanks. Yes there is a param to do that, set form_submit_on_right = False in your SuitConfig class

You can see all available configuration parameters in DjangoSuitConfig base class while docs are under development: https://github.com/darklow/django-suit/blob/v2/suit/apps.py#L44

alexphelps commented 7 years ago

@darklow I just tried the setting. This is the result for me.

image

darklow commented 7 years ago

@alexphelps Looks like I have overridden something while developing new features. Could you please open separate issue, I will take a look, meanwhile please use default settings.

darklow commented 7 years ago

EnclosedInput widget has been ported to v2: image

Demo: http://v2.djangosuit.com/admin/demo/country/170/change/ https://github.com/darklow/django-suit/blob/v2/demo/demo/admin.py#L42

brunotikami commented 7 years ago

hey @darklow! first of all, congrats on the outstanding work with v2. Do you have any thoughts on licensing for v2? Should I buy a v1 license, would it be valid or upgradable for v2? Thanks !

darklow commented 7 years ago

@brunotikami thanks. You'll find answers about licensing v2 here https://github.com/darklow/django-suit/issues/475#issuecomment-186200814 and here http://djangosuit.com/pricing/#v2

darklow commented 7 years ago

Another new feature added to v2 - RelatedFieldAdmin - improved ModelAdmin class that can show any related/FK field as link or text and is not limited by lookup depth (Django supports only direct FK fields). New feature uses current_app param while generating admin links, therefore it should work in multiple admin sites as well.

Usage: Just add link_to_ prefix to any related field.

from suit.admin import RelatedFieldAdmin

class ShowcaseAdmin(RelatedFieldAdmin):
    list_display = ('link_to_user', 'address__city', 'link_to_address__city')

Feature can also be used for form fields or fieldsets, but for that you will have to add field by yourself to readonly_fields and define field getter: https://github.com/darklow/django-suit/blob/v2/demo/demo/admin.py#L244 http://v2.djangosuit.com/admin/demo/showcase/1/change/

Demo: http://v2.djangosuit.com/admin/demo/country/ http://v2.djangosuit.com/admin/demo/showcase/

Overriding short_description or admin_order_field example: https://github.com/darklow/django-suit/blob/v2/demo/demo/admin.py#L241

Screenshot: image

image

ebertti commented 7 years ago

Hi @darklow, about this relataed link, I made this lib, without using mixin or inheritance

I think you don't need to a Base Class for this.

https://github.com/ebertti/django-admin-easy

from django.contrib import admin
import easy

class ShowcaseAdmin(admin.ModelAdmin):
    list_display = ('link_user', 'address__city', 'link_address_city')

    link_user = easy.ForeignKeyAdminField('user')
    link_address_city = easy.ForeignKeyAdminField('address.city')
darklow commented 7 years ago

@ebertti Your library is quite nice indeed, I wasn't aware of it. I explored options using decorators, but wasn't sure it would be easy overriding queryset to add related fields to select_related() so I went with Inheritance which is classic way to extend things and I see nothing wrong with it.

I don't think I am ready to drop feature just yet, but I like how you factored this feature as a separate fields instead of using "magic" link_to_ prefix pattern like I did, so I'll probably rewrite these two existing into something similar.

PS. You should use admin_site current_app variable when generating links to support multiple admin sites. See how Django does it: https://github.com/django/django/blob/master/django/contrib/admin/views/main.py#L386

If you wan't to discuss more about this, let's open separate issue.

Nekmo commented 7 years ago

Thank you very much for your work! :D We are already upgrading from SuitV1 to SuitV2 without problems.

The only thing we miss, and I have not seen in TODO list, is the search. Are you planning to retrieve the search box?

Thank you so much for everything!

darklow commented 7 years ago

Django 1.11 (LTS) was released today and didn't noticed any issues with v2 dev version. Feel free to upgrade to Django 1.11 to get all the great new features: https://docs.djangoproject.com/en/1.11/releases/1.11/

This feature is long awaited one for extending and creating new admin widgets: https://docs.djangoproject.com/en/1.11/releases/1.11/#template-based-widget-rendering

gasinvein commented 7 years ago

Will there be some v1→v2 migration guide?

gamesbook commented 7 years ago

@darklow Can you confirm that suit2.0 will support Django 1.10 and 1.11 going forward?

darklow commented 7 years ago

@gamesbook Yes I can confirm that. Right now I am using v2 in different projects with Django 1.9, 1.10 and 1.11 with no issues so far. At one point in future maybe I will introduce some new widgets that are only supported since Django 1.11, because of the new template based widget system that was introduced in 1.11.

sergwx commented 7 years ago

When i try to add something , main menu always show first item/Model. I do something worng or is a bug? menu_error

gamesbook commented 7 years ago

@SergSergiu see #601