Re: New to Django: Please Help!! Django User Model not saving first_name, last_name and email - Authentication App

2018-10-29 Thread Manjunath
Remove declaration of first_name, last_name & email in Form calss.
class SignUpForm(UserCreationForm):
class meta():
model = User 
fields = ('username', 'first_name', 'last_name', 'email', 
'password1', 'password2', )

 And while Saving the form, follow below steps.
if form.is_valid():
   new_user = form.save(commit=False)
   new_user.set_password(form.cleaned_data['password1'])
  new_user.save()
  # Your next steps


I think you might need to declare password1 & password2 fields in your 
Form. Do Check.



On Monday, October 29, 2018 at 10:04:39 PM UTC+5:30, Adrian Chipukuma wrote:
>
> Hello, 
>
> I am new to Django and enjoying the learning process, unfortunately I am 
> stuck, and I need expert guidance. 
> I am learning through developing a User Authentication System. The system 
> is supposed to have a user registration functionality, login, user profile 
> editing and logout. I have managed to create the login, logout 
> functionalities and the registration functionality partly. The problem is 
> on the registration, I am only able to save the 'username and password ' 
> using django forms, I have written the code for saving the first_name and 
> the last _name as well as email but it seems not to be working, only the 
> 'username and password' are saved.. I think I am missing something though 
> no error comes up. Please anyone to guide me. Thank you.
> the code is as shown below:
>
>
> views.py
> from django.shortcuts import render, redirect
> from django.contrib.auth import authenticate, login, logout
> from django.contrib.auth.models import User
> from django.contrib import auth, messages
> from django.contrib.auth.forms import UserCreationForm
> from django import forms
> from .forms import SignUpForm
>
> def home(request):
> return render(request, 'authenticate/home.html', {})
>
> def login_user(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)
> messages.success(request,('You have been logged in'))
> return redirect('home')
> else:
> messages.success(request,('Error Logging in!'))
> return redirect('login')
> else:
> return render(request, 'authenticate/login.html', {})
>
> def logout_user(request):
> """if request.method =='POST':"""
> logout(request)
> messages.success(request,('You have been logged out'))
> return redirect('home')
>
> def register_user(request):
> if request.method =='POST':
> form = SignUpForm(request.POST)
> if form.is_valid():
> form.save()
> username = form.cleaned_data['username']
> password = form.cleaned_data['password1']
> user = authenticate(username=username, password=password)
> login(request, user)
> messages.success(request,(' Successfully Registered!'))
> return redirect('home')
> else:
> form = SignUpForm()
>
> context = {'form': form }
> return render(request, 'authenticate/register.html', context)
>
> urls.py
>
> from django.urls import path
> from . import views
> urlpatterns = [
> path('', views.home, name="home"),
> path('login/', views.login_user, name="login"),
> path('logout/', views.logout_user, name='logout'),
> path('register/', views.register_user, name='register'),
> ]
>
> forms.py
> from django.contrib.auth.forms import UserCreationForm, UserChangeForm
> from django.contrib.auth.models import User
> from django import forms
>
> class SignUpForm(UserCreationForm):
> email = forms.EmailField()
> first_name = forms.CharField(max_length=100,)
> last_name = forms.CharField(max_length=100,)
> class meta():
> model = User 
> fields = ('username', 'first_name', 'last_name', 'email', 'password1', 
> 'password2', )
>
> register.html
> {% extends 'authenticate/base.html'%}
> {% block content%}
> This is the Registration Page
> 
> {% csrf_token %}
> {% if form.errors %}
> Your form has errors
> {{ error }}
> {% endif %}
> 
> {{ form.as_p }}
> 
> 
> 
> 
> {% endblock %}
>
>
> Chao!
>
> Adrian
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

-- 
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/9a58de45-95d1-4fc6-8948-0cc6994c85fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to subclass AsyncHttpConsumer for a GET request?

2018-10-29 Thread Andrew Godwin
Yup, that's the right way - subclass the async consumer class and then
write a handle method. You have to do your own post/get distinctions, like
in a Django view, but with the scope rather than the request.

Andrew

On Mon, Oct 29, 2018 at 4:37 PM Zhiyu/Drew Li  wrote:

> Not sure if this is the best way. I just found
> inside AsyncHttpConsumer.handle() I can access self.scope['method'] to
> determine if it is a GET or POST or others.
>
> Thanks
> Drew
>
>
>
>
>
>
> On Monday, October 29, 2018 at 3:50:43 PM UTC-6, Zhiyu/Drew Li wrote:
>>
>> Hi there,
>>
>> Newbie to Channels.
>>
>> I am trying to write a Async consumer to handle a http GET request
>> How to write a subclass MyAsynHttpConsumer(AsyncHttpConsumer) for this
>> purpose? Or I am looking at the wrong class?
>>
>> Also if I understand correctly, I should manually add a new pair 'http':
>> MyAsynHttpConsumer to ProtocolTypeRouter()
>>
>> async_http_urlpatterns = [
>> url(r'^async-http/$', consumers. MyAsynHttpConsumer   ),
>> ]
>>
>> ProtocolTypeRouter (
>> 'http': AuthMiddlewareStack(
>> URLRouter(
>>  my_channels_app.routing.async_http_urlpatterns
>> )
>> ),
>> )
>>
>> Thanks
>> Drew
>>
>>
>>
>> --
> 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/8c46871d-6e24-47e1-8813-5721014aedca%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAFwN1uopgpGn7uASW0%2BteonKN8qQFdBXcwA2N8_JM1-CTYiDdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to subclass AsyncHttpConsumer for a GET request?

2018-10-29 Thread Zhiyu/Drew Li
Not sure if this is the best way. I just found 
inside AsyncHttpConsumer.handle() I can access self.scope['method'] to 
determine if it is a GET or POST or others.

Thanks
Drew






On Monday, October 29, 2018 at 3:50:43 PM UTC-6, Zhiyu/Drew Li wrote:
>
> Hi there,
>
> Newbie to Channels.
>
> I am trying to write a Async consumer to handle a http GET request
> How to write a subclass MyAsynHttpConsumer(AsyncHttpConsumer) for this 
> purpose? Or I am looking at the wrong class?
>
> Also if I understand correctly, I should manually add a new pair 'http': 
> MyAsynHttpConsumer to ProtocolTypeRouter()
>
> async_http_urlpatterns = [
> url(r'^async-http/$', consumers. MyAsynHttpConsumer   ),
> ]
>
> ProtocolTypeRouter ( 
> 'http': AuthMiddlewareStack(
> URLRouter(
>  my_channels_app.routing.async_http_urlpatterns
> )
> ),
> )
>
> Thanks
> Drew
>
>
>
>

-- 
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/8c46871d-6e24-47e1-8813-5721014aedca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to subclass AsyncHttpConsumer for a GET request?

2018-10-29 Thread Zhiyu (Drew) Li
Hi there,

Newbie to Channels.

I am trying to write a Async consumer to handle a http GET request
How to write a subclass MyAsynHttpConsumer(AsyncHttpConsumer) for this
purpose? Or I am looking at the wrong class?

Also if I understand correctly, I should manually add a new pair 'http':
MyAsynHttpConsumer to ProtocolTypeRouter()

async_http_urlpatterns = [
url(r'^async-http/$', consumers. MyAsynHttpConsumer   ),
]

ProtocolTypeRouter (
'http': AuthMiddlewareStack(
URLRouter(
 my_channels_app.routing.async_http_urlpatterns
)
),
)

Thanks
Drew

-- 
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/CAMmsbUnBV5x8ZEQ4xDC9v2V7EB%3DvpwnFREhZYTWnc5Xzf93J2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: Handling Database Tables without a unique column

2018-10-29 Thread Matthew Pava
I certainly do hope that it’s filled with more than just junk.  If it truly is 
just junk, scrap it, and create something else.
If you are adding a column named “id”, I don’t think there is a need to set 
managed to False or really do much of anything else with your model.  You could 
rename the columns and tables to match Django conventions.

Something I do with actual “managed = False” models is use a row number window 
statement to calculate the “id” field in the database view rather than use 
concatenation.  But your way may be faster.

Even so, both solutions are handled at the database level, so I’m not sure what 
changes you are asking about on the manager methods.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Dan Davis
Sent: Monday, October 29, 2018 2:14 PM
To: Django users
Subject: Handling Database Tables without a unique column

I am currently leading a team handling a 16 year old database filled with junk. 
 I think it has existed since its HTML application was served by Oracle forms.
We are in production with Django, and turning off the more recent ColdFusion 
version this Thursday.

However, some of our ways of working reflect the deep SQL roots of the team.   
For some tables, we have multi-column unique keys.

At the time I wrote these things, these seemed the best practices:
* For read-only tables, manufacture a unique column through concatenation in a 
corresponding database view.   Base the Django model on the database view.
* For read-write tables, do the work of adding a new unique ID column, but keep 
the table as managed = False.


Now that I am better at thinking in querysets, and can regularly use 
annotations, including F, Subquery and OuterRef expressions, I wonder whether 
there is a better way.   Has anyone ever tried doing this by adding to the SQL 
expressions code to manufacture a unique column in a QuerySet subclass or in 
the ModelManager?


--
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/e5eedb52-0add-4f3c-902b-4e6e9bfe3d05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
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/64a3b97a215b4a91bd535ad2b10c047b%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Handling Database Tables without a unique column

2018-10-29 Thread Dan Davis
I am currently leading a team handling a 16 year old database filled with 
junk.  I think it has existed since its HTML application was served by 
Oracle forms.
We are in production with Django, and turning off the more recent 
ColdFusion version this Thursday.

However, some of our ways of working reflect the deep SQL roots of the 
team.   For some tables, we have multi-column unique keys.

At the time I wrote these things, these seemed the best practices:
* For read-only tables, manufacture a unique column through concatenation 
in a corresponding database view.   Base the Django model on the database 
view.
* For read-write tables, do the work of adding a new unique ID column, but 
keep the table as managed = False.


Now that I am better at thinking in querysets, and can regularly use 
annotations, including F, Subquery and OuterRef expressions, I wonder 
whether there is a better way.   Has anyone ever tried doing this by adding 
to the SQL expressions code to manufacture a unique column in a QuerySet 
subclass or in the ModelManager?


-- 
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/e5eedb52-0add-4f3c-902b-4e6e9bfe3d05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Handling multiple input values for single html form in django

2018-10-29 Thread Xristos Xristoou
 

i have a html form with 3 inputs and steps buttons.

1st step user must put first name and press button 1

2st step user must put last name and press button 2

3st step user must put email and press final button 3

any time where the user press any button then go to next html step.

i want to Handle inputs in my views.py step by step any time where the user 
press any button and not all together in the final submit .

i try t use this code in views.py to take inputs in django backend and now 
work i don't take anything in views.py.(if i change button type from button 
to submit then i take results nut refresh page and i cant go to step 2) 
views.py 

if request.method == 'POST' and 'first_step' in request.POST:
   print '1'
   firstname= request.POST.get('firstname')if request.method == 'POST' and 
'second_step' in request.POST:
print '2'
lastname= request.POST.get('lastname')if request.method == 'POST' and 
'final_step' in request.POST:
print '3'
email= request.POST.get('email')

here the html code :




Form wizard with circular tabs

http://code.jquery.com/jquery-1.11.1.min.js";>
http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js";>














































First 
Name







Save and continue






Last Name




Previous
Save and continue






email






Previous
Save and continue




Completed









   
$(document).ready(function () {
//Initialize tooltips
$('.nav-tabs > li a[title]').tooltip();

//Wizard
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {

var $target = $(e.target);

if ($target.parent().hasClass('disabled')) {
return false;
}
});

$(".next-step").click(function (e) {

var $active = $('.wizard .nav-tabs li.active');
$active.next().removeClass('disabled');
nextTab($active);

});
$(".prev-step").click(function (e) {

var $active = $('.wizard .nav-tabs li.active');
prevTab($active);

});});

function nextTab(elem) {
$(elem).next().find('a[data-toggle="tab"]').click();}
function prevTab(elem) {
$(elem).prev().find('a[data-toggle="tab"]').click();}

//according menu

$(document).ready(function(){
//Add Inactive Class To All Accordion Headers
$('.accordion-header').toggleClass('inactive-header');

//Set The Accordion Content Width
var contentwidth = $('.accordion-header').width();
$('.accordion-content').css({});

//Open The First Accordion Section When Page Loads

$('.accordion-header').first().toggleClass('active-header').toggleClass('inactive-header');
$('.accordion-content').first().slideDown().toggleClass('open-content');

// The Accordion Effect
$('.accordion-header').click(function () {
if($(this).is('.inactive-header')) {

$('.active-header').toggleClass('active-header').toggleClass('inactive-header').next().slideToggle().toggleClass('open-content');

Re: Variable within a Variable

2018-10-29 Thread Jason
sounds like you would be better off with a template tag

On Monday, October 29, 2018 at 1:22:04 PM UTC-4, a.diaz@gmail.com wrote:
>
> Hi,
>
> Is it possible to have a variable within a variable...
>
> For example
>
> *{{ flights.Legs.0|length}} *
>
> is equal to 1 or 2 or basically a integer. Then i would like to connect 
> this to something like:
>
> {{flights.Legs.0.InboundR.*X*.ATime}} where in stead of the X, I would 
> like to have the value of {{ flights.Legs.0|length}}.
>
> I tried something like this,
>
> *{{flights.Legs.0.InboundR.(flights.Legs.0|length).ATime}}*
>
>  and it did not work.
>
> Any help will be extremple appreciated. 
>
> Regards,
>
> Alberto
>

-- 
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/f89bd026-4ce8-441f-a15a-809d026830ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Variable within a Variable

2018-10-29 Thread a . diaz . cantero
Hi,

Is it possible to have a variable within a variable...

For example

*{{ flights.Legs.0|length}} *

is equal to 1 or 2 or basically a integer. Then i would like to connect 
this to something like:

{{flights.Legs.0.InboundR.*X*.ATime}} where in stead of the X, I would like 
to have the value of {{ flights.Legs.0|length}}.

I tried something like this,

*{{flights.Legs.0.InboundR.(flights.Legs.0|length).ATime}}*

 and it did not work.

Any help will be extremple appreciated. 

Regards,

Alberto

-- 
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/3b4b0be4-228c-49d0-a034-95c138822c90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


New to Django: Please Help!! Django User Model not saving first_name, last_name and email - Authentication App

2018-10-29 Thread Adrian Chipukuma
Hello,

I am new to Django and enjoying the learning process, unfortunately I am
stuck, and I need expert guidance.
I am learning through developing a User Authentication System. The system
is supposed to have a user registration functionality, login, user profile
editing and logout. I have managed to create the login, logout
functionalities and the registration functionality partly. The problem is
on the registration, I am only able to save the 'username and password '
using django forms, I have written the code for saving the first_name and
the last _name as well as email but it seems not to be working, only the
'username and password' are saved.. I think I am missing something though
no error comes up. Please anyone to guide me. Thank you.
the code is as shown below:


views.py
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.contrib import auth, messages
from django.contrib.auth.forms import UserCreationForm
from django import forms
from .forms import SignUpForm

def home(request):
return render(request, 'authenticate/home.html', {})

def login_user(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)
messages.success(request,('You have been logged in'))
return redirect('home')
else:
messages.success(request,('Error Logging in!'))
return redirect('login')
else:
return render(request, 'authenticate/login.html', {})

def logout_user(request):
"""if request.method =='POST':"""
logout(request)
messages.success(request,('You have been logged out'))
return redirect('home')

def register_user(request):
if request.method =='POST':
form = SignUpForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
user = authenticate(username=username, password=password)
login(request, user)
messages.success(request,(' Successfully Registered!'))
return redirect('home')
else:
form = SignUpForm()

context = {'form': form }
return render(request, 'authenticate/register.html', context)

urls.py

from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name="home"),
path('login/', views.login_user, name="login"),
path('logout/', views.logout_user, name='logout'),
path('register/', views.register_user, name='register'),
]

forms.py
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from django.contrib.auth.models import User
from django import forms

class SignUpForm(UserCreationForm):
email = forms.EmailField()
first_name = forms.CharField(max_length=100,)
last_name = forms.CharField(max_length=100,)
class meta():
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1',
'password2', )

register.html
{% extends 'authenticate/base.html'%}
{% block content%}
This is the Registration Page

{% csrf_token %}
{% if form.errors %}
Your form has errors
{{ error }}
{% endif %}

{{ form.as_p }}




{% endblock %}


Chao!

Adrian

-- 
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/CAHBk_LKtZ7VP1BrKv_HFYckBAqM%2BMWwjv5WJKjx9bpYkNLd3tw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Identify failed insert field

2018-10-29 Thread Joel Mathew
Yes, usually I print request.POST to check.
On Mon, 29 Oct 2018 at 19:11, Manjunath  wrote:
>
> I think one of the numeric values you are passing is an empty string.
> Django is trying to cast it to int but failing to do so.
>
> Best solution would be to print each values before save() call & you will 
> know which is the error causing column..
>
> Hope it helps!!
>
>
> On Sunday, October 28, 2018 at 8:35:13 AM UTC+5:30, Joel wrote:
>>
>> Is there anyway to identify which database field update failed,
>> instead of a generic message like "ValueError: invalid literal for
>> int() with base 10: ''?
>>
>> For example, I have the following save():
>>
>> tempcust = unconfirmedappointment(name=name, ageyrs=ageyrs,
>> agemnths=agemnths, gender=gender, mobile=phone,
>> docid=doc,clinicid=clinicobj, seldate=seldate, seltime=slot,
>> email=email, address=address, city=city, uniquestring=uniquestring,
>> otp=otp)
>> tempcust.save()
>>
>> Apparently one of the values is wrong for the field. But all I get is
>> the following:
>>
>> 2018-10-28 08:29:48,842 django.request ERRORInternal Server Error:
>> /clinic/madhav/doctor/4/setappointment
>> Traceback (most recent call last):
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/exception.py",
>> line 34, in inner
>> response = get_response(request)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/base.py",
>> line 126, in _get_response
>> response = self.process_exception_by_middleware(e, request)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/base.py",
>> line 124, in _get_response
>> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>>   File "/home/joel/myappointments/clinic/views.py", line 896, in 
>> setappointment
>> tempcust.save()
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
>> line 718, in save
>> force_update=force_update, update_fields=update_fields)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
>> line 748, in save_base
>> updated = self._save_table(raw, cls, force_insert, force_update,
>> using, update_fields)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
>> line 831, in _save_table
>> result = self._do_insert(cls._base_manager, using, fields, update_pk, 
>> raw)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
>> line 869, in _do_insert
>> using=using, raw=raw)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/manager.py",
>> line 82, in manager_method
>> return getattr(self.get_queryset(), name)(*args, **kwargs)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/query.py",
>> line 1136, in _insert
>> return query.get_compiler(using=using).execute_sql(return_id)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
>> line 1288, in execute_sql
>> for sql, params in self.as_sql():
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
>> line 1241, in as_sql
>> for obj in self.query.objs
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
>> line 1241, in 
>> for obj in self.query.objs
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
>> line 1240, in 
>> [self.prepare_value(field, self.pre_save_val(field, obj)) for
>> field in fields]
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
>> line 1182, in prepare_value
>> value = field.get_db_prep_save(value, connection=self.connection)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
>> line 790, in get_db_prep_save
>> return self.get_db_prep_value(value, connection=connection, 
>> prepared=False)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
>> line 785, in get_db_prep_value
>> value = self.get_prep_value(value)
>>   File 
>> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
>> line 1807, in get_prep_value
>> return int(value)
>> ValueError: invalid literal for int() with base 10: ''
>>
>> How to trace which field is problematic, other than manually debugging
>> each variable and seeing if it is non integer? Can django tell me
>> which field is causing the  issue?
>>
>> Sincerely yours,
>>
>> Dr Joel G Mathew
>
> --
> 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 

Re: Identify failed insert field

2018-10-29 Thread Manjunath
I think one of the numeric values you are passing is an empty string.
Django is trying to cast it to int but failing to do so.

Best solution would be to print each values before save() call & you will 
know which is the error causing column..

Hope it helps!!


On Sunday, October 28, 2018 at 8:35:13 AM UTC+5:30, Joel wrote:
>
> Is there anyway to identify which database field update failed, 
> instead of a generic message like "ValueError: invalid literal for 
> int() with base 10: ''? 
>
> For example, I have the following save(): 
>
> tempcust = unconfirmedappointment(name=name, ageyrs=ageyrs, 
> agemnths=agemnths, gender=gender, mobile=phone, 
> docid=doc,clinicid=clinicobj, seldate=seldate, seltime=slot, 
> email=email, address=address, city=city, uniquestring=uniquestring, 
> otp=otp) 
> tempcust.save() 
>
> Apparently one of the values is wrong for the field. But all I get is 
> the following: 
>
> 2018-10-28 08:29:48,842 django.request ERRORInternal Server Error: 
> /clinic/madhav/doctor/4/setappointment 
> Traceback (most recent call last): 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/exception.py",
>  
>
> line 34, in inner 
> response = get_response(request) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/base.py", 
>
> line 126, in _get_response 
> response = self.process_exception_by_middleware(e, request) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/base.py", 
>
> line 124, in _get_response 
> response = wrapped_callback(request, *callback_args, 
> **callback_kwargs) 
>   File "/home/joel/myappointments/clinic/views.py", line 896, in 
> setappointment 
> tempcust.save() 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py", 
> line 718, in save 
> force_update=force_update, update_fields=update_fields) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py", 
> line 748, in save_base 
> updated = self._save_table(raw, cls, force_insert, force_update, 
> using, update_fields) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py", 
> line 831, in _save_table 
> result = self._do_insert(cls._base_manager, using, fields, update_pk, 
> raw) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py", 
> line 869, in _do_insert 
> using=using, raw=raw) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/manager.py", 
>
> line 82, in manager_method 
> return getattr(self.get_queryset(), name)(*args, **kwargs) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/query.py", 
> line 1136, in _insert 
> return query.get_compiler(using=using).execute_sql(return_id) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
>  
>
> line 1288, in execute_sql 
> for sql, params in self.as_sql(): 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
>  
>
> line 1241, in as_sql 
> for obj in self.query.objs 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
>  
>
> line 1241, in  
> for obj in self.query.objs 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
>  
>
> line 1240, in  
> [self.prepare_value(field, self.pre_save_val(field, obj)) for 
> field in fields] 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
>  
>
> line 1182, in prepare_value 
> value = field.get_db_prep_save(value, connection=self.connection) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
>  
>
> line 790, in get_db_prep_save 
> return self.get_db_prep_value(value, connection=connection, 
> prepared=False) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
>  
>
> line 785, in get_db_prep_value 
> value = self.get_prep_value(value) 
>   File 
> "/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
>  
>
> line 1807, in get_prep_value 
> return int(value) 
> ValueError: invalid literal for int() with base 10: '' 
>
> How to trace which field is problematic, other than manually debugging 
> each variable and seeing if it is non integer? Can django tell me 
> which field is causing the  issue? 
>
> Sincerely yours, 
>
> Dr Joel G Mathew 
>

-- 
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 

RE: Identify failed insert field

2018-10-29 Thread Matthew Pava
I usually get this error when I assign an object to a field rather than its pk.
So this is probably where your problem is:
clinicid=clinicobj.pk

-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Joel Mathew
Sent: Saturday, October 27, 2018 10:04 PM
To: django-users@googlegroups.com
Subject: Identify failed insert field

Is there anyway to identify which database field update failed,
instead of a generic message like "ValueError: invalid literal for
int() with base 10: ''?

For example, I have the following save():

tempcust = unconfirmedappointment(name=name, ageyrs=ageyrs,
agemnths=agemnths, gender=gender, mobile=phone,
docid=doc,clinicid=clinicobj, seldate=seldate, seltime=slot,
email=email, address=address, city=city, uniquestring=uniquestring,
otp=otp)
tempcust.save()

Apparently one of the values is wrong for the field. But all I get is
the following:

2018-10-28 08:29:48,842 django.request ERRORInternal Server Error:
/clinic/madhav/doctor/4/setappointment
Traceback (most recent call last):
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/exception.py",
line 34, in inner
response = get_response(request)
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/base.py",
line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/base.py",
line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/joel/myappointments/clinic/views.py", line 896, in setappointment
tempcust.save()
  File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
line 718, in save
force_update=force_update, update_fields=update_fields)
  File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
line 748, in save_base
updated = self._save_table(raw, cls, force_insert, force_update,
using, update_fields)
  File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
line 831, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
line 869, in _do_insert
using=using, raw=raw)
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/db/models/manager.py",
line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/db/models/query.py",
line 1136, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
line 1288, in execute_sql
for sql, params in self.as_sql():
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
line 1241, in as_sql
for obj in self.query.objs
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
line 1241, in 
for obj in self.query.objs
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
line 1240, in 
[self.prepare_value(field, self.pre_save_val(field, obj)) for
field in fields]
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
line 1182, in prepare_value
value = field.get_db_prep_save(value, connection=self.connection)
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 790, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 785, in get_db_prep_value
value = self.get_prep_value(value)
  File 
"/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1807, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: ''

How to trace which field is problematic, other than manually debugging
each variable and seeing if it is non integer? Can django tell me
which field is causing the  issue?

Sincerely yours,

Dr Joel G Mathew

-- 
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/CAA%3Diw_-5bzYQfCw2BY38rDSS4aFkR48YC-zMDCWbiTDorRs%3DgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe 

Re: Trigger actions independently of url request

2018-10-29 Thread Mario R. Osorio
I'm far from being an expert but I think yours is a rather simple operation 
that needs to be executed every n minutes.

I think that in the case you're explaining, Celery is an overkill. Why not 
go with a cron job?
You might want to create a combination of bash and python scripts to do 
exactly what you need but you'll have a whole lot less headaches.


On Monday, October 22, 2018 at 12:29:19 PM UTC-4, Charley Paulus wrote:
>
> Hi, 
>
> After reading the Django tutorial, my understanding (I hope I’m wrong) is 
> that the only way to trigger a function of a Django app is when someone on 
> the client side request the url related to that function. 
>
> But what if I want the server to run a function indenpendently of a url 
> call, for example: 
> - every 10 minutes 
> - when a pre-defined combination of variables become true 
>
> Where should such code live? 
>
> Thank you. 
> Best regards, 
> Charley

-- 
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/af077eff-9e90-44ae-8ae0-050e986e830a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many field in ModelForm - with tens of thousands of records

2018-10-29 Thread Web Architect
Hi Sanjay,

Thanks for the prompt response and the approach. 

That seems to be an efficient approach - would look into auto-complete.

Thanks.

On Monday, October 29, 2018 at 5:09:50 PM UTC+5:30, Sanjay Bhangar wrote:
>
> My recommendation would be to use a bit of Javascript to implement an 
> "autocomplete" to fetch records via AJAX as the user types (with 
> perhaps a minimum of 3 characters or so), so you only ever fetch a 
> subset of records and don't overload your template. 
>
> You can find quite a few 3rd party libraries that should be able to 
> aid in setting up this behaviour, see: 
> https://djangopackages.org/grids/g/auto-complete/ - unfortunately, I 
> can't recommend a particular one right now - but most should have 
> integrations for the django admin / django forms with Many2Many or 
> ForeignKey fields. 
>
> Hope that helps, 
> Sanjay 
> On Mon, Oct 29, 2018 at 5:01 PM Web Architect  > wrote: 
> > 
> > Would also add that the server CPU usage was hitting 100% due to the 
> template loading issue. 
> > 
> > On Monday, October 29, 2018 at 4:48:54 PM UTC+5:30, Web Architect wrote: 
> >> 
> >> Hi, 
> >> 
> >> We are using django 1.11 for our ecommerce site. 
> >> 
> >> We are facing an issue with modelform and many to many field in it as 
> follows: 
> >> 
> >> Lets say there are two models: 
> >> 
> >> class A(models.Model): 
> >>c = models.CharField() 
> >> 
> >> class B(models.Model): 
> >>   a = models.ManyToManyField('A') 
> >> 
> >> Now if I define a modelform: 
> >> 
> >> class MF(models.ModelForm): 
> >>   class Meta: 
> >>   model = B 
> >>   fields = [a,] 
> >> 
> >> We are using django widget tweaks to render the fields in MF. Now if 
> there are tens of thousands of records in A, the MF form rendering causes 
> the page to hang as the widget will try to show the whole set of tens of 
> thousands of records option for field a. 
> >> 
> >> Hence, would appreciate if anyone could suggest a smart solution 
> wherein the above issue is taken care of. 
> >> 
> >> Thanks. 
> >> 
> >> 
> > -- 
> > 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...@googlegroups.com . 
> > To post to this group, send email to django...@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/36ebab2d-7440-40bc-b5e9-a4a2897dcd3a%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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/e7590f4d-2658-4c8a-bfba-02a5d64cbb12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many field in ModelForm - with tens of thousands of records

2018-10-29 Thread Sanjay Bhangar
My recommendation would be to use a bit of Javascript to implement an
"autocomplete" to fetch records via AJAX as the user types (with
perhaps a minimum of 3 characters or so), so you only ever fetch a
subset of records and don't overload your template.

You can find quite a few 3rd party libraries that should be able to
aid in setting up this behaviour, see:
https://djangopackages.org/grids/g/auto-complete/ - unfortunately, I
can't recommend a particular one right now - but most should have
integrations for the django admin / django forms with Many2Many or
ForeignKey fields.

Hope that helps,
Sanjay
On Mon, Oct 29, 2018 at 5:01 PM Web Architect  wrote:
>
> Would also add that the server CPU usage was hitting 100% due to the template 
> loading issue.
>
> On Monday, October 29, 2018 at 4:48:54 PM UTC+5:30, Web Architect wrote:
>>
>> Hi,
>>
>> We are using django 1.11 for our ecommerce site.
>>
>> We are facing an issue with modelform and many to many field in it as 
>> follows:
>>
>> Lets say there are two models:
>>
>> class A(models.Model):
>>c = models.CharField()
>>
>> class B(models.Model):
>>   a = models.ManyToManyField('A')
>>
>> Now if I define a modelform:
>>
>> class MF(models.ModelForm):
>>   class Meta:
>>   model = B
>>   fields = [a,]
>>
>> We are using django widget tweaks to render the fields in MF. Now if there 
>> are tens of thousands of records in A, the MF form rendering causes the page 
>> to hang as the widget will try to show the whole set of tens of thousands of 
>> records option for field a.
>>
>> Hence, would appreciate if anyone could suggest a smart solution wherein the 
>> above issue is taken care of.
>>
>> Thanks.
>>
>>
> --
> 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/36ebab2d-7440-40bc-b5e9-a4a2897dcd3a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAG3W7ZHLEPgUKqZWfLh2yqJc6wkoAMbeY_iw5zDk%2BOJHqJejOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many field in ModelForm - with tens of thousands of records

2018-10-29 Thread Web Architect
Would also add that the server CPU usage was hitting 100% due to the 
template loading issue. 

On Monday, October 29, 2018 at 4:48:54 PM UTC+5:30, Web Architect wrote:
>
> Hi,
>
> We are using django 1.11 for our ecommerce site. 
>
> We are facing an issue with modelform and many to many field in it as 
> follows:
>
> Lets say there are two models:
>
> class A(models.Model):
>c = models.CharField()
>
> class B(models.Model):
>   a = models.ManyToManyField('A')
>
> Now if I define a modelform:
>
> class MF(models.ModelForm):
>   class Meta:
>   model = B
>   fields = [a,]
>
> We are using django widget tweaks to render the fields in MF. Now if there 
> are tens of thousands of records in A, the MF form rendering causes the 
> page to hang as the widget will try to show the whole set of tens of 
> thousands of records option for field a. 
>
> Hence, would appreciate if anyone could suggest a smart solution wherein 
> the above issue is taken care of. 
>
> Thanks.
>
>
>

-- 
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/36ebab2d-7440-40bc-b5e9-a4a2897dcd3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Many to Many field in ModelForm - with tens of thousands of records

2018-10-29 Thread Web Architect
Hi,

We are using django 1.11 for our ecommerce site. 

We are facing an issue with modelform and many to many field in it as 
follows:

Lets say there are two models:

class A(models.Model):
   c = models.CharField()

class B(models.Model):
  a = models.ManyToManyField('A')

Now if I define a modelform:

class MF(models.ModelForm):
  class Meta:
  model = B
  fields = [a,]

We are using django widget tweaks to render the fields in MF. Now if there 
are tens of thousands of records in A, the MF form rendering causes the 
page to hang as the widget will try to show the whole set of tens of 
thousands of records option for field a. 

Hence, would appreciate if anyone could suggest a smart solution wherein 
the above issue is taken care of. 

Thanks.


-- 
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/2b3be3a1-e0a6-4c73-8c69-d7a314885ab3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Field Name in Models

2018-10-29 Thread Dennis Alabi
I want to start developing a surveillance security system. Please what 
field name should i use for live feed from camera in my models.py. Please 
your response will be appreciated.

-- 
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/db847948-fe21-41d8-976c-a5fbf8d4478c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.