def redirect_if_authenticated(view_func):
@wraps(view_func)
def dispatch_wrapper(self, request, *args, **kwargs):
if request.user.is_athenticated:
return redirect('default')
return view_func(self, request, *args, **kwargs)
return dispatch_wrapper
crm/crm/settings.py
AUTH_USER_MODEL = "profiles.CRMUser"
crm/profiles/models.py
from django.contrib.auth.models import AbstractUser
from django.db import models
class CRMUser(AbstractUser):
org = models.ForeignKey('main.Organization', null=True, blank=True)
def __str__(self):
return '{} / {}'.format(self.username, self.org.name if self.org else "")
class Meta:
verbose_name = 'Пользователь'
verbose_name_plural = 'Пользователи'
from profiles.models import CRMUser
def get_date_diff(self):
return (self.checkout - self.checkin).days
def get_date_diff(self):
return [self.checkout + datetime.timedelta(i) for i in range((self.checkout - self.checkin).days)]
get_readonly_fileds
change_*
, редактировать он по факту не сможет, т.к. все поля будут закрыты для изменения.class BaseAdmin(admin.ModelAdmin):
def get_readonly_fields(self, request, obj=None):
if 'имя группы пользователей' in [g.name for g in request.user.groups.all()]:
return self.get_fields(request, obj)
return None
BaseAdmin
, чтобы вручную не переопределять этот метод.@admin.register(MyModel)
class MyModelAdmin(BaseAdmin):
pass
Доступно начиная с django 1.7
project/myapp/apps.py
from django.apps import AppConfig
class MyAppConfig(AppConfig):
name = "myapp"
verbose_name = "Моё приложение"
project/myapp/__init__.py
default_app_config = "myapp.apps.MyAppConfig"
for i in request.GET:
if item.id == i:
continue
if item.id !=i and item.id in request.GET.keys():
continue
if item.id !=i and item.id not in request.GET.keys():
book_image.delete()
else:
# пропустим try
image = Image.obejcts.get(id=i)
book_img = BookImages(book=book, image=image)
book_img.save()