from django import forms
from  django.contrib.auth.forms import UserCreationForm
from .models import Comment
from django.contrib.auth import get_user_model

User = get_user_model()
#create forms
class NewUserForm(UserCreationForm):
    email = forms.EmailField(required=True)
    
    class Meta:
        model = User
        fields = ("username", "email","<PASSWORD>","<PASSWORD>")
    def __init__(self, *args, **kwargs):
        super(NewUserForm, self).__init__(*args, **kwargs)

        for fieldname in ['username', 'password1', '<PASSWORD>']:
            self.fields[fieldname].help_text = None
        
    def save(self, commit=True):
        user = super(NewUserForm, self).save(commit=False)
        user.email = self.cleaned_data['email']
        if commit:
            user.save()
        return user
class CommentForm(forms.ModelForm):
    content = forms.CharField(widget=forms.Textarea(attrs={
        'rows': '4',
    }))
    class Meta:
        model = Comment
        fields = ('content',)
        
from django import forms
from  django.contrib.auth.forms import UserCreationForm
from .models import Comment
from django.contrib.auth import get_user_model

User = get_user_model()
#create forms
class NewUserForm(UserCreationForm):
    email = forms.EmailField(required=True)
    
    class Meta:
        model = User
        fields = ("username", "email","<PASSWORD>","<PASSWORD>")
    def __init__(self, *args, **kwargs):
        super(NewUserForm, self).__init__(*args, **kwargs)

        for fieldname in ['username', 'password1', '<PASSWORD>']:
            self.fields[fieldname].help_text = None
        
    def save(self, commit=True):
        user = super(NewUserForm, self).save(commit=False)
        user.email = self.cleaned_data['email']
        if commit:
            user.save()
        return user
class CommentForm(forms.ModelForm):
    content = forms.CharField(widget=forms.Textarea(attrs={
        'rows': '4',
    }))
    class Meta:
        model = Comment
        fields = ('content',)
        
#create forms