diff --git a/app/demo/profile/__init__.py b/app/demo/profile/__init__.py new file mode 100644 index 00000000..e017cac8 --- /dev/null +++ b/app/demo/profile/__init__.py @@ -0,0 +1 @@ +default_app_config = 'demo.profile.apps.ProfileConfig' \ No newline at end of file diff --git a/app/demo/profile/admin.py b/app/demo/profile/admin.py new file mode 100644 index 00000000..82894282 --- /dev/null +++ b/app/demo/profile/admin.py @@ -0,0 +1,23 @@ +from django.contrib import admin + +from demo.profile.model import UserProfile +from material.admin import MaterialUserAdmin +from material.decorators import register +from material.sites import site + +from django.contrib.auth.models import User + + +site.unregister(User) + + +class UserPictureInline(admin.TabularInline): + model = UserProfile + extra = 0 + + +@register(User) +class MaterialUserPictureAdmin(MaterialUserAdmin): + """Register User model with material styles""" + inlines = [UserPictureInline] + diff --git a/app/demo/profile/apps.py b/app/demo/profile/apps.py new file mode 100644 index 00000000..6c73dacd --- /dev/null +++ b/app/demo/profile/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ProfileConfig(AppConfig): + name = 'demo.profile' + icon_name = 'layers' diff --git a/app/demo/profile/migrations/0001_initial.py b/app/demo/profile/migrations/0001_initial.py new file mode 100644 index 00000000..d8a5f580 --- /dev/null +++ b/app/demo/profile/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# Generated by Django 2.2.3 on 2019-07-06 12:03 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='UserProfile', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('picture', models.FileField(blank=True, null=True, upload_to='', verbose_name='User Picture')), + ('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'Picture', + 'verbose_name_plural': 'Picture', + 'db_table': 'user_pictures', + }, + ), + ] diff --git a/app/demo/profile/migrations/__init__.py b/app/demo/profile/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/demo/profile/model.py b/app/demo/profile/model.py new file mode 100644 index 00000000..36629a52 --- /dev/null +++ b/app/demo/profile/model.py @@ -0,0 +1,23 @@ +from django.conf import settings +from django.db import models +from django.utils.translation import gettext_lazy as _ + + +class UserProfile(models.Model): + user = models.OneToOneField( + settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, + related_name='profile', + null=True, + blank=True + ) + picture = models.FileField( + _('User Picture'), + null=True, + blank=True + ) + + class Meta: + verbose_name = _('Picture') + verbose_name_plural = _('Picture') + db_table = 'user_pictures' diff --git a/app/demo/settings.py b/app/demo/settings.py index 009d4015..f7ccfdda 100644 --- a/app/demo/settings.py +++ b/app/demo/settings.py @@ -40,6 +40,7 @@ 'django.contrib.staticfiles', 'django.contrib.sites', + 'demo.profile', 'demo.countries', 'demo.documents', 'demo.relations', diff --git a/material/templates/material/side_nav.html b/material/templates/material/side_nav.html index ab998d8c..154d44a1 100644 --- a/material/templates/material/side_nav.html +++ b/material/templates/material/side_nav.html @@ -6,7 +6,9 @@
  • - {% if user.picture %} + {% if user.profile.picture %} + + {% elif user.picture %} {% else %} diff --git a/package/material/options.py b/package/material/options.py index 22be1c9c..f891fd52 100644 --- a/package/material/options.py +++ b/package/material/options.py @@ -13,8 +13,6 @@ }, models.TimeField: {'widget': widgets.MaterialAdminTimeWidget}, models.TextField: {'widget': widgets.MaterialAdminTextareaWidget}, - models.ImageField: {'widget': widgets.MaterialAdminFileWidget}, - models.FileField: {'widget': widgets.MaterialAdminFileWidget}, } diff --git a/package/material/templates/material/widgets/clearable_file_input.html b/package/material/templates/admin/widgets/clearable_file_input.html similarity index 100% rename from package/material/templates/material/widgets/clearable_file_input.html rename to package/material/templates/admin/widgets/clearable_file_input.html diff --git a/package/material/templates/material/side_nav.html b/package/material/templates/material/side_nav.html index ab998d8c..154d44a1 100644 --- a/package/material/templates/material/side_nav.html +++ b/package/material/templates/material/side_nav.html @@ -6,7 +6,9 @@
  • - {% if user.picture %} + {% if user.profile.picture %} + + {% elif user.picture %} {% else %} diff --git a/package/material/widgets.py b/package/material/widgets.py index eb7fb2f4..718ff6c6 100644 --- a/package/material/widgets.py +++ b/package/material/widgets.py @@ -24,11 +24,6 @@ class MaterialAdminTimeWidget(forms.TimeInput): template_name = 'material/widgets/time.html' -class MaterialAdminFileWidget(widgets.AdminFileWidget): - """File input with material css styles""" - template_name = 'material/widgets/clearable_file_input.html' - - class MaterialAdminTextareaWidget(widgets.AdminTextareaWidget): """Textarea with material css styles""" diff --git a/package/setup.py b/package/setup.py index 789406ea..3cbd1b8f 100644 --- a/package/setup.py +++ b/package/setup.py @@ -10,7 +10,7 @@ setup( name="django-material-admin", - version="1.1.3", + version="1.1.4", packages=find_packages(), author="Anton Maistrenko", include_package_data=True,