...
nstance.paypal_address = validated_data('paypal_address', instance.paypal_address)
instance.ebay_id = validated_data('ebay_id', instance.ebay_id)
instance.resellers_permit_number = validated_data('resellers_permit_number', instance.resellers_permit_number)
# видимо подразумевалось validated_data.get('paypal_address', instance.paypal_address) и тд
....
from allauth.account import views as account_views
urlpatterns = [
...
url(r'^customlogin/$', account_views.login, name='account_login'),
url(r'^customlogout/$', account_views.logout, name='account_logout'),
url(r'^accounts/', include('allauth.urls')),
...
]
from django.apps import apps
@receiver(pre_migrate, sender=apps.get_app_config('auth'))
def add_user_permissions(sender, **kwargs):
content_type = ContentType.objects.get_for_model(settings.AUTH_USER_MODEL)
Permission.objects.get_or_create(codename='view_user', name=' Can view users', content_type=content_type)
Permission.objects.get_or_create(codename='change_user_password', name=' Can change user password', content_type=content_type)
...
def forwards_func(apps, schema_editor):
User = apps.get_model('auth', 'User')
Permission = apps.get_model('auth', 'Permission')
ContentType = apps.get_model('contenttypes', 'ContentType')
content_type = ContentType.objects.get_for_model(User)
db_alias = schema_editor.connection.alias
Permission.objects.using(db_alias).bulk_create([
Permission(codename='view_user', name=' Can view users', content_type=content_type),
Permission.objects.get_or_create(codename='change_user_password', name=' Can change user password', content_type=content_type)
])
...
from django.forms import ModelMultipleChoiceField
class CustomModelMultipleChoiceField(ModelMultipleChoiceField):
def label_from_instance(self, obj):
"""
Тут, собственно, и определяется,
что за текст будет в чоисах.
"""
return obj.name
class UserEditForm(UserChangeForm):
user_permissions = CustomModelMultipleChoiceField(queryset=Permission.objects.all(), required=False)
...
class UserEditForm(UserChangeForm):
def __init__(self, *args, **kwargs):
super(UserEditForm, self).__init__(*args, **kwargs)
user_permissions_field = self.fields['user_permissions']
user_permissions_field.widget.choices = user_permissions_field.queryset.values_list('pk', 'name')