Re: How to Add to Django Administration Using Code

2020-10-11 Thread Dvs Khamele
Hi do you hire contract based python/django freelancer?
 I can help you in this and related tasks
Best Regards,
Divyesh Khamele

On Sun, 11 Oct 2020, 9:59 pm Let's Get Going,  wrote:

> Hi everyone. I have created a Django chat app for testing. Two days ago it
> was working fine. But from yesterday it is not working as expected. I don't
> know where the mistake is.
> Can anyone help me with that please?
> I am pasting form, models,signup html page and views code.
> or if anyone want to help me live then I can share the link of live share
> or anydesk code.
>
> #Django-Form
>
> from .models import User_Info
> from django.forms import ModelForm
> from django.contrib.auth.models import User
> from django.contrib.auth.forms import UserCreationForm
> from django import forms
>
>
> class updateForm(ModelForm):
>
> class Meta:
> model=User_Info
> fields='__all__'
> exclude=['user']
>
>
> class CustomUserCreateForm(UserCreationForm):
> class Meta:
> model=User
> fields=['username','password1','password2','email','first_name',
> 'last_name']
>
> def same_password(self):
> password1=self.cleaned_data['password1']
> password2=self.cleaned_data['password2']
> try:
> password1=password2
> except:
> raise forms.ValidationError('Passwords are not same.')
> return password1
>
>
>
>
> #Django-Views
>
> from django.shortcuts import render
> from django.urls import reverse
> from django.http import HttpResponseRedirect
> from django.contrib.auth import login,logout,authenticate
> from .models import  User_Info
> from django.contrib import messages
> from django.contrib.auth.models import User
> from . import forms
>
> # Create your views here.
>
> def index(request):
> return render(request,'LC/index.html')
>
> def login_view(request):
> if not request.user.is_authenticated:
> return HttpResponseRedirect(reverse('loginForm'))
> return HttpResponseRedirect(reverse('my_profile'))
>
> def login_request(request):
> if request.method=='POST':
> username=request.POST['username']
> password=request.POST['password']
> user=authenticate(request,username=username,password=password)
> if user is not None:
> login(request,user)
> return HttpResponseRedirect(reverse('login'))
> else:
> return render(request,'LC/login.html',{
> 'message':'Invalid Credentials.',
> 'create_message':'Not registered?'
>
> })
> return render(request,'LC/login.html',{'message':'Login'})
>
> def signup_view(request):
> form=forms.CustomUserCreateForm()
> if request.method=='POST':
> form=forms.CustomUserCreateForm(request.POST)
> if form.is_valid():
> username=request.POST['username']
> password=request.POST['password1']
> form.save()
> user=authenticate(request,username=username,password=password)
> if user is not None:
> login(request,user)
> return HttpResponseRedirect(reverse('my_profile'))
> else:
> return render(request,'LC/signup.html',{'form':form,'message':
> 'Fill all the fields.'})
> return render(request,'LC/signup.html',{'form':form})
>
> def my_profile(request):
> if not request.user.is_authenticated:
> return HttpResponseRedirect(reverse('index'))
> form=forms.updateForm(instance=request.user.user_info)
> if request.method=="POST":
> form=forms.updateForm(request.POST,request.FILES,instance
> =request.user.user_info)
> if form.is_valid():
> form.save()
> return render(request,'LC/my_profile.html',{'form':form})
>
> def users(request):
> if not request.user.is_authenticated:
> return HttpResponseRedirect(reverse('index'))
> users=User.objects.all()
> return render(request,'LC/users.html',{'users':users})
>
> def chats(request):
> if not request.user.is_authenticated:
> return HttpResponseRedirect(reverse('index'))
> return render(request,'LC/chats.html')
>
> def logout_view(request):
> logout(request)
> return render(request,'LC/login.html',{'message':'Logged Out.'})
>
> #Django-Models
>
> from django.db import models
> from django.contrib.auth.models import User
> from django.db.models.signals import post_save
> # Create your models here.
>
>
> class User_Info(models.Model):
> user=models.OneToOneField(User,null=True,on_delete=models.CASCADE)
>
> about=models.TextField(null=True,max_length=1000)
> profile_pic=models.ImageField(default='defaultUser.png',null=True,
> blank=True)
>
>
> def create_info(sender,**kwargs):
> if kwargs['created']:
> user_info=User_Info.objects.create(user=kwargs['instance'])
>
> post_save.connect(create_info,sender=User)
>
>
> #Html- Signup Form
>
> {%load static%}
> 
> 
> 
>"image/x-icon">
>   
>   
>   

Re: How to Add to Django Administration Using Code

2020-10-11 Thread Let's Get Going
Hi everyone. I have created a Django chat app for testing. Two days ago it
was working fine. But from yesterday it is not working as expected. I don't
know where the mistake is.
Can anyone help me with that please?
I am pasting form, models,signup html page and views code.
or if anyone want to help me live then I can share the link of live share
or anydesk code.

#Django-Form

from .models import User_Info
from django.forms import ModelForm
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from django import forms


class updateForm(ModelForm):

class Meta:
model=User_Info
fields='__all__'
exclude=['user']


class CustomUserCreateForm(UserCreationForm):
class Meta:
model=User
fields=['username','password1','password2','email','first_name',
'last_name']

def same_password(self):
password1=self.cleaned_data['password1']
password2=self.cleaned_data['password2']
try:
password1=password2
except:
raise forms.ValidationError('Passwords are not same.')
return password1




#Django-Views

from django.shortcuts import render
from django.urls import reverse
from django.http import HttpResponseRedirect
from django.contrib.auth import login,logout,authenticate
from .models import  User_Info
from django.contrib import messages
from django.contrib.auth.models import User
from . import forms

# Create your views here.

def index(request):
return render(request,'LC/index.html')

def login_view(request):
if not request.user.is_authenticated:
return HttpResponseRedirect(reverse('loginForm'))
return HttpResponseRedirect(reverse('my_profile'))

def login_request(request):
if request.method=='POST':
username=request.POST['username']
password=request.POST['password']
user=authenticate(request,username=username,password=password)
if user is not None:
login(request,user)
return HttpResponseRedirect(reverse('login'))
else:
return render(request,'LC/login.html',{
'message':'Invalid Credentials.',
'create_message':'Not registered?'

})
return render(request,'LC/login.html',{'message':'Login'})

def signup_view(request):
form=forms.CustomUserCreateForm()
if request.method=='POST':
form=forms.CustomUserCreateForm(request.POST)
if form.is_valid():
username=request.POST['username']
password=request.POST['password1']
form.save()
user=authenticate(request,username=username,password=password)
if user is not None:
login(request,user)
return HttpResponseRedirect(reverse('my_profile'))
else:
return render(request,'LC/signup.html',{'form':form,'message':
'Fill all the fields.'})
return render(request,'LC/signup.html',{'form':form})

def my_profile(request):
if not request.user.is_authenticated:
return HttpResponseRedirect(reverse('index'))
form=forms.updateForm(instance=request.user.user_info)
if request.method=="POST":
form=forms.updateForm(request.POST,request.FILES,instance
=request.user.user_info)
if form.is_valid():
form.save()
return render(request,'LC/my_profile.html',{'form':form})

def users(request):
if not request.user.is_authenticated:
return HttpResponseRedirect(reverse('index'))
users=User.objects.all()
return render(request,'LC/users.html',{'users':users})

def chats(request):
if not request.user.is_authenticated:
return HttpResponseRedirect(reverse('index'))
return render(request,'LC/chats.html')

def logout_view(request):
logout(request)
return render(request,'LC/login.html',{'message':'Logged Out.'})

#Django-Models

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
# Create your models here.


class User_Info(models.Model):
user=models.OneToOneField(User,null=True,on_delete=models.CASCADE)

about=models.TextField(null=True,max_length=1000)
profile_pic=models.ImageField(default='defaultUser.png',null=True,blank=
True)


def create_info(sender,**kwargs):
if kwargs['created']:
user_info=User_Info.objects.create(user=kwargs['instance'])

post_save.connect(create_info,sender=User)


#Html- Signup Form

{%load static%}



  
  
  
  Sign Up | Let's Chat https://fonts.googleapis.com/css2?family=PT+Serif=swap; rel=
"stylesheet">
  



{%if message%}
{{message}}
{%endif%}
  
{%csrf_token%}
{{form.username.label}}
{{form.username}}
{{form.first_name.label}}
{{form.first_name}}
{{form.last_name.label}}
{{form.last_name}}
{{form.email.label}}
{{form.email}} 
{{form.password1.label}}
{{form.password1}} 
{{form.password2.label}}
{{form.password2}} 
Create
  

Re: How to Add to Django Administration Using Code

2020-09-21 Thread coolguy

further to my previous comments please share the your related model code to 
make discussion interesting...
On Sunday, September 20, 2020 at 11:35:05 AM UTC-4 Lightning Bit wrote:

> Hi all, 
>
> I am trying to figure out how to add "Customers" using code. Please look 
> at the administration layout: 
>
> [image: HELP.png]
>
> I was able to add to "Groups" using the following code in "views.py": 
>
> *@unauthenticated_user*
> *def registerPage(request):*
>
> *form = CreateUserForm()*
>
> *if request.method == 'POST':*
> *form = CreateUserForm(request.POST)*
> *if form.is_valid():*
> *user = form.save()*
> *username = form.cleaned_data.get('username')*
> 
> *group = Group.objects.get(name='customer')*
> *user.groups.add(group)*
> 
>
>
>
> *messages.success(request, 'BOLT Force account was 
> created for' + username )*
> *return redirect('login')*
>
> *data= cartData(request)*
>
> *items=data['items']*
> *order=data['order']*
> *cartItems=data['cartItems']*
>
> *products = Product.objects.all()*
>
> *context = {'products':products, 'items':items, 'order':order, 
> 'cartItems':cartItems, 'form':form}*
> *return render(request, 'store/register.html', context)*
>
> However, I am unsure of how to add to the "Customers" section of the 
> picture above. I have tried almost every technique with no luck. I wanted 
> both the "Groups" and the "Customers" to have the same registered person 
> added at once. Would anyone happen to know how to fix this? 
>
> Thank you!
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/76689278-42d6-4fbf-83d1-248b2a9721b8n%40googlegroups.com.


Re: How to Add to Django Administration Using Code

2020-09-21 Thread coolguy
do want to add the picture file to the customer application or want to see 
the picture in admin?

On Sunday, September 20, 2020 at 11:35:05 AM UTC-4 Lightning Bit wrote:

> Hi all, 
>
> I am trying to figure out how to add "Customers" using code. Please look 
> at the administration layout: 
>
> [image: HELP.png]
>
> I was able to add to "Groups" using the following code in "views.py": 
>
> *@unauthenticated_user*
> *def registerPage(request):*
>
> *form = CreateUserForm()*
>
> *if request.method == 'POST':*
> *form = CreateUserForm(request.POST)*
> *if form.is_valid():*
> *user = form.save()*
> *username = form.cleaned_data.get('username')*
> 
> *group = Group.objects.get(name='customer')*
> *user.groups.add(group)*
> 
>
>
>
> *messages.success(request, 'BOLT Force account was 
> created for' + username )*
> *return redirect('login')*
>
> *data= cartData(request)*
>
> *items=data['items']*
> *order=data['order']*
> *cartItems=data['cartItems']*
>
> *products = Product.objects.all()*
>
> *context = {'products':products, 'items':items, 'order':order, 
> 'cartItems':cartItems, 'form':form}*
> *return render(request, 'store/register.html', context)*
>
> However, I am unsure of how to add to the "Customers" section of the 
> picture above. I have tried almost every technique with no luck. I wanted 
> both the "Groups" and the "Customers" to have the same registered person 
> added at once. Would anyone happen to know how to fix this? 
>
> Thank you!
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/91e61ad8-1a47-4b73-b0cf-7053056e6a21n%40googlegroups.com.


How to Add to Django Administration Using Code

2020-09-20 Thread Lightning Bit
Hi all, 

I am trying to figure out how to add "Customers" using code. Please look at 
the administration layout: 

[image: HELP.png]

I was able to add to "Groups" using the following code in "views.py": 

*@unauthenticated_user*
*def registerPage(request):*

*form = CreateUserForm()*

*if request.method == 'POST':*
*form = CreateUserForm(request.POST)*
*if form.is_valid():*
*user = form.save()*
*username = form.cleaned_data.get('username')*

*group = Group.objects.get(name='customer')*
*user.groups.add(group)*



*messages.success(request, 'BOLT Force account was created 
for' + username )*
*return redirect('login')*

*data= cartData(request)*

*items=data['items']*
*order=data['order']*
*cartItems=data['cartItems']*

*products = Product.objects.all()*
*context = {'products':products, 'items':items, 'order':order, 
'cartItems':cartItems, 'form':form}*
*return render(request, 'store/register.html', context)*

However, I am unsure of how to add to the "Customers" section of the 
picture above. I have tried almost every technique with no luck. I wanted 
both the "Groups" and the "Customers" to have the same registered person 
added at once. Would anyone happen to know how to fix this? 

Thank you!

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f26749b-7c0f-4f50-970e-892e2f5cb2cfn%40googlegroups.com.