I need create link in my admin part of site, for models AccountUser and AccountUserInfo
-------------------------- My models.py -------------------------- import imghdr import string import datetime from django_countries.fields import CountryField from django.db import models from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin from django.core.urlresolvers import reverse from django.core.exceptions import ValidationError from django.core.validators import MinLengthValidator from django.conf import settings from libs.validators import OnlyLowercaseAndDigits ALLOWED_CHARS = string.ascii_lowercase + string.digits MAX_LENGTH = 8 class AccountUserManager(*BaseUserManager*): """ Manager for my user model """ def create_user(self, email, name, password=None): """ Creates and saves a user with the given email, name of account and password. """ if not email: raise ValueError('User must have an email address') if not name: raise ValueError('User must have a name of account') user = self.model(email=self.normalize_email(email), name=name) user.set_password(password) user.save() return user def create_superuser(self, email, name, password): """ Creates and saves a superuser with the given email, name of account and password. """ if not password: raise ValueError('Superuser must be have a password') user = self.create_user(email=self.normalize_email(email), name=name, password=password) user.is_superuser = True user.save() return user def make_random_password(self, length=10, allowed_chars=ALLOWED_CHARS): return super().make_random_password(length, allowed_chars) class AccountUser(*AbstractBaseUser*, *PermissionsMixin*): """ Model for users, registering by email and unique name of account """ email = models.EmailField('Email of account', max_length=50, unique=True) name = models.CharField('Account of name', max_length=50, validators=[ OnlyLowercaseAndDigits, MinLengthValidator(MAX_LENGTH, 'Field must be at least {0} chars'.format(MAX_LENGTH)), ]) is_active = models.BooleanField(default=True) date_joined = models.DateTimeField('Date joined', auto_now_add=True) objects = AccountUserManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = ['name'] class Meta: db_table = 'account_user' verbose_name = "AccountUser" verbose_name_plural = "AccountUsers" get_latest_by = 'date_joined' ordering = ['-date_joined'] def __str__(self): return '{0.email}'.format(self) def save(self, *args, **kwargs): try: self.full_clean() except ValidationError as errors_message: print('Was happened next errors:\n-----------------------------') for error in errors_message: print(error) else: super().save(*args, **kwargs) account = AccountUser.objects.get(email=self.email) if not hasattr(account, 'accountuserinfo'): AccountUserInfo.objects.create(account=account) def get_absolute_url(self): return reverse('app_accounts:account_profile') def get_full_name(self): return '{0.name} ({0.email})'.format(self) def clean(self): if len(self.password) < MAX_LENGTH: raise ValidationError({ 'password': 'Length of password must be at least {0}'.format(MAX_LENGTH) }) if all(i in string.digits for i in self.password): raise ValidationError({ 'password': 'Your password can\'t be entirely numeric' }) def get_short_name(self): return '{0.email}'.format(self) @property def is_staff(self): return self.is_superuser class AccountUserInfo(models.Model): MAN = 'man' WOMAN = 'woman' VAGUE = 'vague' GENDER_CHOICES = [ (VAGUE, 'Vague'), (MAN, 'Male'), (WOMAN, 'Female'), ] def dispatch_account_media_files(instance, filename): return '{0}/app_accounts/{1}'.format(instance.account.__str__(), filename) account = models.OneToOneField(AccountUser, on_delete=models.CASCADE) first_name = models.CharField('First name', max_length=50, blank=True, null=True) last_name = models.CharField('Last name', max_length=50, blank=True, null=True) picture = models.ImageField('Picture', upload_to=dispatch_account_media_files, blank=True, null=True) gender = models.CharField('Gender', max_length=10, choices=GENDER_CHOICES, default=GENDER_CHOICES[0][0]) country = CountryField('Country', blank_label='(select country)', blank=True, null=True) birthday = models.DateField('Birthday', blank=True, null=True) # theme # language class Meta: db_table = 'account_user_info' verbose_name = "UserAccountInfo" verbose_name_plural = "UserAccountInfo" # order_with_respect_to = ['account'] def __str__(self): return self.account.__str__() def save(self, *args, **kwargs): try: self.full_clean() except ValidationError as errors_message: print('Was happened next errors:\n-----------------------------') for error in errors_message: print(error) else: super().save(*args, **kwargs) def get_absolute_url(self): return self.account.get_absolute_url() def clean(self): if isinstance(self.birthday, datetime.date): start_date = datetime.date(year=1900, month=1, day=1) end_date = datetime.date.today() if not start_date <= self.birthday <= end_date: raise ValidationError({'birthday': ('Date can be in range from {0} to {1}'.format(start_date, end_date))}) if self.picture: if not imghdr.what(self.picture): raise ValidationError({'picture': ('It is not image. Please select image in format PNG, GIF, JPEG')}) @property def account_user_picture(self): if self.picture: return self.picture.url else: return settings.STATIC_URL + 'project_static/images/accountuser_default_picture.png' --------------------------- My admin.py --------------------------- from django.contrib import admin from django.contrib.auth.models import Group from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from .forms import FormAccountUserCreation, FormAccountUserChange from .models import AccountUser, AccountUserInfo class AdminAccountUserInline(admin.StackedInline): model = AccountUserInfo class AdminAccountUser(*BaseUserAdmin*): actions = ['make_non_superuser', 'make_superuser', 'delete_selected'] form = FormAccountUserChange add_form = FormAccountUserCreation list_display = ('email', 'name', 'is_superuser') list_filter = ('is_superuser',) fieldsets = ( ('Personal info', {'fields': ('email', 'name', 'password',)}), ('Permissions', {'fields': ('is_superuser',)}), ) add_fieldsets = ( (None, { 'classes': ('wide',), 'fields': ('email', 'name', 'password1', 'password2') }), ) search_fields = ('email', 'name') ordering = ('email', 'name') * inlines = ['AdminAccountUserInline']* def make_non_superuser(self, request, queryset): """ Admin action by selected users will be non-superusers """ row_updated = queryset.update(is_superuser=False) if row_updated == 1: message = 'Succefull update paramets one user'.format(row_updated) else: message = 'Succefull update paramets {} users'.format(row_updated) self.message_user(request, message) make_non_superuser.short_description = 'Make selected user as non-superuser' def make_superuser(self, request, queryset): """ Admin action by selected users will be superusers """ row_updated = queryset.update(is_superuser=True) if row_updated == 1: message = 'Succefull update paramets one user'.format(row_updated) else: message = 'Succefull update paramets {} users'.format(row_updated) self.message_user(request, message) make_superuser.short_description = 'Make selected user as superuser' admin.site.register(AccountUser, AdminAccountUser) admin.site.register(AccountUserInfo) admin.site.unregister(Group) But if I wrote in AdminAccountUser next text inlines = ['AdminAccountUserInline'] I have next traceback ------------------------------------ File "/home/wlysenko/.virtualenvs/virtual_PersonalDicts/project_PersonalDicts/project_PersonalDicts/urls.py", line 7, in <module> from .admin import admin_site_PersonalDicts File "/home/wlysenko/.virtualenvs/virtual_PersonalDicts/project_PersonalDicts/project_PersonalDicts/admin.py", line 7, in <module> from apps.app_accounts.admin import AdminAccountUser File "/home/wlysenko/.virtualenvs/virtual_PersonalDicts/project_PersonalDicts/apps/app_accounts/admin.py", line 60, in <module> admin.site.register(AccountUser, AdminAccountUser) File "/home/wlysenko/.virtualenvs/virtual_PersonalDicts/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 109, in register system_check_errors.extend(admin_obj.check()) File "/home/wlysenko/.virtualenvs/virtual_PersonalDicts/lib/python3.4/site-packages/django/contrib/admin/options.py", line 113, in check return self.checks_class().check(self, **kwargs) File "/home/wlysenko/.virtualenvs/virtual_PersonalDicts/lib/python3.4/site-packages/django/contrib/admin/checks.py", line 498, in check errors.extend(self._check_inlines(admin_obj)) File "/home/wlysenko/.virtualenvs/virtual_PersonalDicts/lib/python3.4/site-packages/django/contrib/admin/checks.py", line 536, in _check_inlines for index, item in enumerate(obj.inlines) File "/home/wlysenko/.virtualenvs/virtual_PersonalDicts/lib/python3.4/site-packages/django/contrib/admin/checks.py", line 536, in <listcomp> for index, item in enumerate(obj.inlines) File "/home/wlysenko/.virtualenvs/virtual_PersonalDicts/lib/python3.4/site-packages/django/contrib/admin/checks.py", line 541, in _check_inlines_item inline_label = '.'.join([inline.__module__, inline.__name__]) AttributeError: 'str' object has no attribute '__module__' May someone know how realize this link in admin Djnago? Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4b7a76af-550d-403a-8bb2-50109b9f6199%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.