daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #TODO: MODEL ADMIN E PAI DOS DEMAIS MODELS DE LOGIN
  2. class CustomUser(AbstractBaseUser):
  3.     email = models.EmailField(_('E-mail '), max_length=255, unique=True)
  4.     username = models.CharField(_('Nome de usuário '), max_length=15, unique=True)
  5.     choice = models.BooleanField(default=False)
  6.     ft = models.ImageField(upload_to='fotos', null=True, blank=True, default='../media/site/user.png')
  7.     date_joined = models.CharField(_('Data de início '), max_length=20, default=timezone.now())
  8.     is_active = models.BooleanField(default=True)
  9.     is_admin = models.BooleanField(default=False)
  10.     USERNAME_FIELD = 'email'
  11.     REQUIRED_FIELDS = ['username', 'choice']
  12.     objects = UserManager()
  13.     class Meta:
  14.         verbose_name = _('Usuário')
  15.         verbose_name_plural = _('Usuários')
  16.     def __str__(self):
  17.         return self.username
  18.     def has_perm(self, perm, obj=None):
  19.         return True
  20.     def has_module_perms(self, app_label):
  21.         return True
  22.     @property
  23.     def is_staff(self):
  24.         return self.is_admin
  25.    
  26. class CustomCompanyCreationForm(UserCreationForm):
  27.         class Meta(UserCreationForm.Meta):
  28.             model = CustomCompany
  29.             fields = ('name', 'departamento', 'cnpj', 'ft', 'telefone','cep', 'endereco', 'cidade', 'uf', 'username', 'email'
  30.                   )
  31.    
  32. {% load widget_tweaks %}
  33.  
  34. {% for hidden_field in form.hidden_fields %}
  35.   {{ hidden_field }}
  36. {% endfor %}
  37.  
  38. {% if form.non_field_errors %}
  39.   <div class="alert alert-danger" role="alert">
  40.     {% for error in form.non_field_errors %}
  41.       {{ error }}
  42.     {% endfor %}
  43.   </div>
  44. {% endif %}
  45.  
  46. {% for field in form.visible_fields %}
  47.   <div class="form-group">
  48.     <hr>
  49.     {{ field.label_tag }}
  50.  
  51.     {% if form.is_bound %}
  52.       {% if field.errors %}
  53.         {% render_field field class="form-control is-invalid placeholder=form.text.label" %}
  54.         {% for error in field.errors %}
  55.           <div class="invalid-feedback">
  56.             {{ error }}
  57.           </div>
  58.         {% endfor %}
  59.       {% else %}
  60.         {% render_field field class="form-control is-valid placeholder=form.text.label" %}
  61.       {% endif %}
  62.     {% else %}
  63.       {% render_field field class="form-control" placeholder=form.text.label %}
  64.     {% endif %}
  65.  
  66.     {% if field.help_text %}
  67.       <small class="form-text text-muted">{{ field.help_text|safe }}</small>
  68.     {% endif %}
  69.   </div>
  70. {% endfor %}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top