i currently try to "style" my registration form. in General i get the 
concept behind it but not at that point:


This is how it's intendet to be (and not working):

    class RegistrationForm(UserCreationForm):
>         username = forms.CharField(required=True, label='Username', 
> widget=forms.TextInput(attrs={'class': 'class-one-input-fields'}))
>         password1 = forms.CharField(required=True, label='Password', 
> widget=forms.PasswordInput(attrs={'class': 'class-one-input-fields'}))
>         password2 = forms.CharField(required=True, label='Password 
> confirmation', widget=forms.PasswordInput(attrs={'class': 
> 'class-one-input-fields'}))
>         pubpgp = forms.CharField(required=True, label='Public PGP Key', 
> widget=forms.Textarea(attrs={'class': 'class-two-input-fields'}))
>         captcha = CaptchaField()
>     
>         def save(self, commit=True):
>             username = super(RegistrationForm, self).save(commit=False)
>             username.pubpgp = self.cleaned_data['pubpgp']
>     
>             if commit:
>                 username.save()
>     
>             return username


views.py:

    def signup (request):
>         if request.method == 'POST':
>             form = RegistrationForm(request.POST)
>             if form.is_valid():
>                 form.save()
>                 messages.add_message(request, messages.INFO, "Thanks for 
> you registration, you are now able to login.")
>                 return redirect(reverse('post_list'))
>         else:
>             form = RegistrationForm()
>     
>             args = {'form': form}
>             return render(request, 'registration/signup.html', args)


The error i get is:

> AttributeError: Manager isn't available; 'auth.User' has been swapped
> > for 'accounts.User'


in my settings.py i set:

> AUTH_USER_MODEL = 'accounts.User'


This is the current working state:

    class RegistrationForm(UserCreationForm):
>         user = forms.CharField(required=True)
>     
>         class Meta:
>             model = User
>             fields = (
>                 'user',
>                 'password1',
>                 'password2',
>                 'pubpgp'
>             )
>     
>         captcha = CaptchaField()
>     
>         def save(self, commit=True):
>             user = super(RegistrationForm, self).save(commit=False)
>             user.pubpgp = self.cleaned_data['pubpgp']
>     
>             if commit:
>                 user.save()
>     
>             return user


User model of accounts:

    #User Model Manager
>     class UserManager(BaseUserManager):
>         def create_user(self, user, password=None):
>             """
>             Creates and saves a User with the given username and password.
>             """
>             if not user:
>                 raise ValueError('Error: The User you want to create must 
> have a username, try again')
>     
>             new_user = self.model(
>                 user=self.model.normalize_username(user)
>             )
>     
>             new_user.set_password(password)
>             new_user.save(using=self._db)
>             return new_user
>     
>         def create_staffuser(self, user, password):
>             """
>             Creates and saves a staff user with the given username and 
> password.
>             """
>             new_user = self.create_user(
>                 user,
>                 password=password,
>             )
>             new_user.staff = True
>             new_user.save(using=self._db)
>             return new_user
>     
>         def create_superuser(self, user, password):
>             """
>             Creates and saves a superuser with the given username and 
> password.
>             """
>             new_user = self.create_user(
>                 user,
>                 password=password,
>             )
>             new_user.staff = True
>             new_user.admin = True
>             new_user.save(using=self._db)
>             return new_user
>     
>     
>     class User(AbstractBaseUser):
>     
>         #User fields
>         user = 
> models.CharField(verbose_name='username',max_length=30,unique=True)
>         bio = models.TextField(max_length=5000, blank=True, null=True)
>         pubpgp = models.TextField(blank=True, null=True)
>         avatar = fields.ImageField(upload_to='avatar', blank=True, 
> null=True, dependencies=[
>             FileDependency(processor=ImageProcessor(
>                 format='JPEG', scale={'max_width': 350, 'max_height': 
> 350}))
>         ])
>     
>         #Account typs
>         active = models.BooleanField(default=True)
>         staff = models.BooleanField(default=False) # a admin user; non 
> super-user
>         admin = models.BooleanField(default=False) # a superuser
>         # notice the absence of a "Password field", that's built in.
>     
>         USERNAME_FIELD = 'user'
>         REQUIRED_FIELDS = [] # Username & Password are required by default.
>     
>         def get_full_name(self):
>             # The user is identified by their Username ;)
>             return self.user
>     
>         def get_short_name(self):
>             # The user is identified by their Username address
>             return self.user
>         def __str__(self):
>             return self.user
>     
>         def has_perm(self, perm, obj=None):
>             """Does the user have a specific permission?"""
>             # Simplest possible answer: Yes, always
>             return True
>     
>         def has_module_perms(self, app_label):
>             """Does the user have permissions to view the app 
> `app_label`?"""
>             # Simplest possible answer: Yes, always
>             return True
>     
>         @property
>         def is_staff(self):
>             """Is the user a member of staff?"""
>             return self.staff
>     
>         @property
>         def is_admin(self):
>             """Is the user a admin member?"""
>             return self.admin
>     
>         @property
>         def is_active(self):
>             """Is the user active?"""
>             return self.active
>     
>         objects = UserManager()


i guess that i have to pass the User model into this form somehow. Any idea 
about the syntax?


-- 
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/ad1df517-48ca-4379-913c-e94f32cc063f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to