Admin case-insensitive sorting question

2018-01-09 Thread Mike Dewhirst
I have tried every which way to produce a case-insenstive list of 
substances in the Admin including this:


def get_queryset(self, request):
    return super(SubstanceAdmin, 
self).get_queryset(request).order_by(Lower('name').asc())


Which DOES work (as proven via print statement) but doesn't display that 
way in the Admin which uses the natural ascii order. It is the 
list_display feature which re-orders the substances.


I can get them sorting pseudo-insensitively by using a method to 
uppercase the first char of the name and passing that method to 
list_display.


However, that prevents the column order reversal feature which is a 
function of the list_display feature.


I thought a case insensitive model manager might work until I saw in the 
docs that subsequent order_by filtering will spoil it and I would still 
have to pseudo_name them anyway.


So the question is ... should I bite the bullet and add a sort field to 
the model and fill it with the substance name converted to lower-case?


Thanks

Mike

--
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/b1fc1d23-b0ab-d35e-9049-9a4f6091a4f7%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: I can't install easy install

2018-01-09 Thread Peter of the Norse
This is the second time I’ve seen this and need to let you know it’s not true.  
PowerShell doesn’t have elevated permissions, it’s just bash for .NET.  While 
there are a bunch of new scripting features built into it, it has no effect on 
Python* or any other commands you might run.

- Peter of the Norse
> 
> It is probably best to avoid using Powershell unless you have a strong 
> preference. It gives you permissions which might lead you to developing 
> software which assumes it has those permissions. I might be wrong there but I 
> haven't had any difficulties using the ordinary shell.
> 
> Welcome Henry

*  This might not be true if you are running IronPython, but it was never 
updated to 3, so it doesn’t matter.

-- 
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/4D802920-3CC6-4F7B-B393-0203783D409C%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Convert Excel code to Python

2018-01-09 Thread BIJAL MANIAR

Hi,
Thanks all for reply.
Since it is an old application there is no documentation for it. I will 
have to do Reverse Engineering by looking at vbscript code and gathering 
requirements.
Total there are 40 screens. A single form has 20-30 input parameters to 
select from and generate output depending on that. There are validation for 
combination of few input parameters as well. I can code in python but want 
some suggestion on approach to be followed.

I know fully automated tools are not available. Has anyone used vb2py or 
any such libraries for such requirement and how accurate it was?

Thanks,
Bijal

On Tuesday, January 9, 2018 at 6:45:55 PM UTC+5:30, BIJAL MANIAR wrote:
>
>
> Hi,
>
> There is an old application in Excel where macros are coded in VBScript 
> and there is both frontend (forms) and backend in Excel. Need to replicate 
> it as a web application (Python, Django, React). From scratch, have to 
> build it in python.
> I have checked vb2py library is there for code conversion but it has 
> limitations. Can anyone please guide me if any tools are available to 
> convert code from vbscript to python? 
>
> Thanks,
> Bijal
>
>

-- 
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/69a6524b-ffbc-4c32-bba6-7c6e40746832%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django how to make user model username unique=False

2018-01-09 Thread cherngyorng
The reason is because i want to add some user without entering their 
username. As i manage to allow null input for username but the unique for 
username make it an error if i add another user without username. These 
user are used for adding family member. For eg creating a 3 years old baby 
profile as family member.

On Wednesday, January 10, 2018 at 10:41:44 AM UTC+9, chern...@gmail.com 
wrote:
>
> Thanks for these improvement. But the main thing i want is to make 
> username field unique = false
>
> On Tuesday, January 9, 2018 at 5:39:32 PM UTC+9, chern...@gmail.com wrote:
>>
>> I am trying to make username unique = false as there are cases where 
>> username is not needed. Since i am using email address to login.
>> But with the django user model, how do i customise it ? 
>>
>> Here is the code for my current user model:
>>
>> from django.db import models
>> from django.contrib.auth.models import AbstractUser
>> from django.contrib.auth.models import UserManager
>> from django.db.models import Q
>> from django.core.validators import RegexValidator
>>
>>
>> class CustomUserManager(UserManager):
>>
>> def get_by_natural_key(self, username):
>> return self.get(
>> # this comment is to prevent user from using username to login
>> # Q(**{self.model.USERNAME_FIELD: username}) |
>> Q(**{self.model.EMAIL_FIELD: username})
>> )
>>
>>
>> class MyUser(AbstractUser):
>> userId = models.AutoField(primary_key=True)
>> gender = models.CharField(max_length=6, blank=True, null=True)
>> nric = models.CharField(max_length=40, blank=True, null=True)
>> birthday = models.DateField(blank=True, null=True)
>> birthTime = models.TimeField(blank=True, null=True)
>> ethnicGroup = models.CharField(max_length=30, blank=True, null=True)
>> favoriteClinic = models.CharField(max_length=50, blank=True, null=True)
>> appVer = models.CharField(max_length=50, blank=True, null=True)
>> osVer = models.CharField(max_length=50, blank=True, null=True)
>> mobileType = models.IntegerField(blank=True, null=True)
>> country_code = models.IntegerField(blank=True, null=True)
>> # mobile_regex = RegexValidator(regex=r'^(\+\d{1,3})?,?\s?\d{8,13}$', 
>> message="Phone number must not consist of space and requires country code. 
>> eg : +6591258565")
>> mobileNo = models.CharField(max_length=25, blank=True, null=True)  # 
>> validators should be a list
>> height = models.FloatField(blank=True, null=True)
>> weight = models.FloatField(blank=True, null=True)
>> bloodtype = models.CharField(max_length=3, blank=True, null=True)
>> allergy = models.CharField(max_length=30, blank=True, null=True)
>> # image1 = models.ImageField(upload_to=)
>> # image = models.BinaryField(editable=True, blank=True, null=True)
>> # displaypicture = models.ImageField
>> objects = CustomUserManager()
>>
>> def __str__(self):
>> return self.username
>>
>>

-- 
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/64c1269c-240b-4d65-8bab-0ee19a353b4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django how to make user model username unique=False

2018-01-09 Thread cherngyorng
Thanks for these improvement. But the main thing i want is to make username 
field unique = false

On Tuesday, January 9, 2018 at 5:39:32 PM UTC+9, chern...@gmail.com wrote:
>
> I am trying to make username unique = false as there are cases where 
> username is not needed. Since i am using email address to login.
> But with the django user model, how do i customise it ? 
>
> Here is the code for my current user model:
>
> from django.db import models
> from django.contrib.auth.models import AbstractUser
> from django.contrib.auth.models import UserManager
> from django.db.models import Q
> from django.core.validators import RegexValidator
>
>
> class CustomUserManager(UserManager):
>
> def get_by_natural_key(self, username):
> return self.get(
> # this comment is to prevent user from using username to login
> # Q(**{self.model.USERNAME_FIELD: username}) |
> Q(**{self.model.EMAIL_FIELD: username})
> )
>
>
> class MyUser(AbstractUser):
> userId = models.AutoField(primary_key=True)
> gender = models.CharField(max_length=6, blank=True, null=True)
> nric = models.CharField(max_length=40, blank=True, null=True)
> birthday = models.DateField(blank=True, null=True)
> birthTime = models.TimeField(blank=True, null=True)
> ethnicGroup = models.CharField(max_length=30, blank=True, null=True)
> favoriteClinic = models.CharField(max_length=50, blank=True, null=True)
> appVer = models.CharField(max_length=50, blank=True, null=True)
> osVer = models.CharField(max_length=50, blank=True, null=True)
> mobileType = models.IntegerField(blank=True, null=True)
> country_code = models.IntegerField(blank=True, null=True)
> # mobile_regex = RegexValidator(regex=r'^(\+\d{1,3})?,?\s?\d{8,13}$', 
> message="Phone number must not consist of space and requires country code. eg 
> : +6591258565")
> mobileNo = models.CharField(max_length=25, blank=True, null=True)  # 
> validators should be a list
> height = models.FloatField(blank=True, null=True)
> weight = models.FloatField(blank=True, null=True)
> bloodtype = models.CharField(max_length=3, blank=True, null=True)
> allergy = models.CharField(max_length=30, blank=True, null=True)
> # image1 = models.ImageField(upload_to=)
> # image = models.BinaryField(editable=True, blank=True, null=True)
> # displaypicture = models.ImageField
> objects = CustomUserManager()
>
> def __str__(self):
> return self.username
>
>

-- 
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/1b1ca8d0-18cb-4d51-908e-9be551cdb8b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Convert Excel code to Python

2018-01-09 Thread John Fabiani
There are several libs available that deal with excel.  I normally just use
xlwt.  But, if memory serves, xlwing does something with vba.

I've never used xlwing so I might completely wrong.  Either way check out
all the python libs for excel.
Johnf

On Tue, Jan 9, 2018 at 4:27 PM, RM T  wrote:

>
> Use third-party libraries
> 在 2018年1月9日星期二 UTC+8下午9:15:55,BIJAL MANIAR写道:
>>
>>
>> Hi,
>>
>> There is an old application in Excel where macros are coded in VBScript
>> and there is both frontend (forms) and backend in Excel. Need to replicate
>> it as a web application (Python, Django, React). From scratch, have to
>> build it in python.
>> I have checked vb2py library is there for code conversion but it has
>> limitations. Can anyone please guide me if any tools are available to
>> convert code from vbscript to python?
>>
>> Thanks,
>> Bijal
>>
>> --
> 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/14166316-e249-4150-ba79-015ff1308194%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/CANDKt83YsZqAeCZM5Uc1kLggHP%2BgN3%3DzZW%3D9c4UzfRXdtR7NzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Newbie : Help for using RequestContext

2018-01-09 Thread Mickael . barbo
Hello to all Django users :-)

I'm new to Django and this is my first post.

I'd like to implement breadcrumbs on all my pages.

My strategy is to create a middleware and to use RequestContext to
add a dict to the context of each request then use the context in my html

My problem is that I don't understand how to link RequestContext to 
my request. Hereafter my code :

my_middleware.py
from django.template import RequestContext


class SimpleBreadcrumbs(object):
def __init__(self, get_response):
self.get_response = get_response
# One-time configuration and initialization.


def __call__(self, request):
# Code to be executed for each request before
# the view (and later middleware) are called.

request_context = RequestContext(request)
request_context.push({"level0": "Adrian", "level1": "Thomas"})

response = self.get_response(request)


# Code to be executed for each request/response after
# the view is called.

return response


my_template.html

{% extends 'pricing/body.html' %}

{% block content %}

{{ level0 }}

{% endblock content %}


What I'm doing wrong ?

Thx for your help

Micka
Django newbie
;-)





-- 
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/6cf0e65a-2b48-4bbb-a8a7-0351252e49f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Convert Excel code to Python

2018-01-09 Thread RM T

Use third-party libraries
在 2018年1月9日星期二 UTC+8下午9:15:55,BIJAL MANIAR写道:
>
>
> Hi,
>
> There is an old application in Excel where macros are coded in VBScript 
> and there is both frontend (forms) and backend in Excel. Need to replicate 
> it as a web application (Python, Django, React). From scratch, have to 
> build it in python.
> I have checked vb2py library is there for code conversion but it has 
> limitations. Can anyone please guide me if any tools are available to 
> convert code from vbscript to python? 
>
> Thanks,
> Bijal
>
>

-- 
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/14166316-e249-4150-ba79-015ff1308194%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can you people explain why the def _str_() method is used below?

2018-01-09 Thread Furbee
Who you call "you people?" Just kidding.

On Tue, Jan 9, 2018 at 11:27 AM,  wrote:

> Thanks alot James and Projec.Your posts were very helpful to me.
>
> --
> 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/70139b94-cc0f-4e93-bb97-42009d41a10f%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/CACMDPqFZh-17%3DULsuixiob%3D7VkWMYFgPnUVjqK0y34T69ZZv3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can you people explain why the def _str_() method is used below?

2018-01-09 Thread utpalbrahma1995
Thanks alot James and Projec.Your posts were very helpful to me.

-- 
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/70139b94-cc0f-4e93-bb97-42009d41a10f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django test command with --parallel

2018-01-09 Thread Yevhen Yevhen
I try to run my django tests using --parallel flag but get the following error 
(pastebin) . How can I fix this?

-- 
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/d866583d-1fd5-47ce-9363-85737ef13d35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Convert Excel code to Python

2018-01-09 Thread Jason
Are you able to write the code yourself?  Might be better that way.

-- 
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/bc1d2b01-6e58-4b74-b999-224efc04aa16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: urlopen error [Errno 110] Connection timed out

2018-01-09 Thread Jason
Are you able to load the URL directly in the browser without issue?  How 
about using an API client like Postman?  

-- 
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/166363d5-578a-4ac2-8151-b478ddf62d6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Convert Excel code to Python

2018-01-09 Thread BIJAL MANIAR

Hi,

There is an old application in Excel where macros are coded in VBScript and 
there is both frontend (forms) and backend in Excel. Need to replicate it 
as a web application (Python, Django, React). From scratch, have to build 
it in python.
I have checked vb2py library is there for code conversion but it has 
limitations. Can anyone please guide me if any tools are available to 
convert code from vbscript to python? 

Thanks,
Bijal

-- 
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/01179ad1-41ae-4d05-bf65-3cb7bd43e53f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: urlopen error [Errno 110] Connection timed out

2018-01-09 Thread suase9303
Thanks.!

I had better use an async task worker! i need to study the worker...

the error happens with a specific URL.



2018년 1월 9일 화요일 오후 8시 7분 15초 UTC+9, Jason 님의 말:
>
> You really should use an async task worker like Celery for this, to get 
> the scraping outside of Django's request-response loop.
>
> Is the urlopen happening with any specific URL or seemingly at random?
>

-- 
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/57576a10-fa38-4817-8afa-7fec87ec8f28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django rest framework foreign key display details from table 1 to table 2

2018-01-09 Thread Jason
What you are looking for is nested serialization.  There's a section in the 
DRF docs on this 

 that 
should provide some light.  Fortunately, your serializers are almost there.

-- 
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/2c7507db-502c-479d-8a39-e26592c54c2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: urlopen error [Errno 110] Connection timed out

2018-01-09 Thread Jason
You really should use an async task worker like Celery for this, to get the 
scraping outside of Django's request-response loop.

Is the urlopen happening with any specific URL or seemingly at random?

-- 
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/5fe18bd7-4501-4ac9-9a44-fa536dafdd8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error following django's documentation 2.0

2018-01-09 Thread FernandoJMM
Good morning,

I think the error comes from making modifications to django's settings.
I started the project again and now the django shell works.

Thanks for your interest !!!
Fernando

El sábado, 6 de enero de 2018, 7:51:01 (UTC+1), Matemática A3K escribió:
>
>
>
> On Fri, Jan 5, 2018 at 8:32 PM, FernandoJMM  > wrote:
>
>> Hello everyone,
>>
>> I'm learning django. I am in the official documentation of django link:
>>
>> *https://docs.djangoproject.com/en/2.0/intro/overview/ 
>> *
>>
>> After creating the model and doing the migrate I go to the section called 
>> *Enjoy 
>> the free API* to test in the python terminal 
>>
>
> Did you get to that python terminal by "python manage.py shell" on the 
> base directory of your project?
>  
>
>> and I get an error when executing the *import*, it says that it can not 
>> find the module.
>>
>> *The only difference with the documentation* is that I am executing it 
>> from a *virtualenv*.
>>
>> it can be fixed ?
>>
>
> I think so :) 
>  
>
>>
>> Thank you all
>>
>> -- 
>> 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/c9941c85-2a42-439f-8999-856507f5f74d%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/d2302294-e824-4796-afed-93f023bdb2a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django how to make user model username unique=False

2018-01-09 Thread Andréas Kühne
Hi,

This is how I created my User model that does what you require:

class User(AbstractBaseUser, PermissionsMixin, AuditableModel):
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)
email = models.EmailField(_('email address'), blank=False,
null=False, unique=True)
is_staff = models.BooleanField(
_('staff status'),
default=False,
help_text=_('Designates whether the user can log into this
admin site.'),
)
is_active = models.BooleanField(
_('active'),
default=True,
help_text=_(
'Designates whether this user should be treated as active. '
'Unselect this instead of deleting accounts.'
),
)
objects = CustomUserManager()

EMAIL_FIELD = 'email'
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []

def clean(self):
"""
Override the default clean method to include normalization of
the email field.
"""
super().clean()
self.email = self.__class__.objects.normalize_email(self.email)

def get_full_name(self):
"""
Returns the first_name plus the last_name, with a space in
between if set, otherwise the email address.
"""
full_name = f'{self.first_name} {self.last_name}'.strip()

if not full_name:
full_name = self.email

return full_name

def get_short_name(self):
"Returns the short name for the user."
return self.first_name

class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')


The reason for the CustomUserManager is to override some methods when
creating users.

By setting the USERNAME_FIELD to 'email' you can remove the
CustomUserManager that you have declared (which by the way I don't think
will work). You can check here for more information about creating your own
user model with email as username field:
https://www.fomfus.com/articles/how-to-use-email-as-username-for-django-authentication-removing-the-username

Here you can also see the CustomUserManager that will be required. :-)

Regards,

Andréas

2018-01-09 9:39 GMT+01:00 :

> I am trying to make username unique = false as there are cases where
> username is not needed. Since i am using email address to login.
> But with the django user model, how do i customise it ?
>
> Here is the code for my current user model:
>
> from django.db import models
> from django.contrib.auth.models import AbstractUser
> from django.contrib.auth.models import UserManager
> from django.db.models import Q
> from django.core.validators import RegexValidator
>
>
> class CustomUserManager(UserManager):
>
> def get_by_natural_key(self, username):
> return self.get(
> # this comment is to prevent user from using username to login
> # Q(**{self.model.USERNAME_FIELD: username}) |
> Q(**{self.model.EMAIL_FIELD: username})
> )
>
>
> class MyUser(AbstractUser):
> userId = models.AutoField(primary_key=True)
> gender = models.CharField(max_length=6, blank=True, null=True)
> nric = models.CharField(max_length=40, blank=True, null=True)
> birthday = models.DateField(blank=True, null=True)
> birthTime = models.TimeField(blank=True, null=True)
> ethnicGroup = models.CharField(max_length=30, blank=True, null=True)
> favoriteClinic = models.CharField(max_length=50, blank=True, null=True)
> appVer = models.CharField(max_length=50, blank=True, null=True)
> osVer = models.CharField(max_length=50, blank=True, null=True)
> mobileType = models.IntegerField(blank=True, null=True)
> country_code = models.IntegerField(blank=True, null=True)
> # mobile_regex = RegexValidator(regex=r'^(\+\d{1,3})?,?\s?\d{8,13}$', 
> message="Phone number must not consist of space and requires country code. eg 
> : +6591258565 <+65%209125%208565>")
> mobileNo = models.CharField(max_length=25, blank=True, null=True)  # 
> validators should be a list
> height = models.FloatField(blank=True, null=True)
> weight = models.FloatField(blank=True, null=True)
> bloodtype = models.CharField(max_length=3, blank=True, null=True)
> allergy = models.CharField(max_length=30, blank=True, null=True)
> # image1 = models.ImageField(upload_to=)
> # image = models.BinaryField(editable=True, blank=True, null=True)
> # displaypicture = models.ImageField
> objects = CustomUserManager()
>
> def __str__(self):
> return self.username
>
> --
> 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 

Re: How do I make a Django model from a tab-delimited data file?

2018-01-09 Thread Andréas Kühne
Kasper,

You are correct :-), I just assumed (probably incorrectly) that the data
was just like his example - in that case it would have been easiest :-)

Regards,

Andréas

2018-01-09 9:27 GMT+01:00 Kasper Laudrup :

> Hi,
>
> On 2018-01-09 08:09, Andréas Kühne wrote:
>
>> You will have to parse the CSV file manually with a custom management
>> command (at least that is what I would do). All you need to do is open the
>> file, split each row with a "," and then  import the correct columns to the
>> model.
>>
>
> Unfortunately, CSV is a really bad, non-standardized format and simply
> splitting each row with a "," will cause you all kinds of issues with
> espacing values with a "," and other things.
>
> I would suggest using the python CSV library for this:
>
> https://docs.python.org/3/library/csv.html
>
> Just though that was worth mentioning.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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/ms
> gid/django-users/83268fb2-22f6-2d6e-c14c-0015d77c48f0%40stacktrace.dk.
>
> 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/CAK4qSCcFzovjvS8M4sgTd8euRcWKWCgqC2xJWcu_qjCvuqdpaw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-09 Thread Kasper Laudrup

Hi Antonis,

On 2018-01-09 07:14, Antonis Christofides wrote:

Ah, OK, sorry I didn't read all the discussion. So I guess that if you keep that
in a global variable, it won't work if your Django app is running in many
processes. (Besides, global variables are rarely a good idea.)



I agree completely that global variables should be avoided. I find them 
to be even more problematic in a language like python where they could 
be instatiated by simply importing a file/module. That's probably OK for 
a simple value like an integer, but I prefer imports not to have too 
many side effects.



If I understand the problem correctly, what I would do would probably be to
touch a file whenever I make a change and examine the file modification date
each time—if it's more recent than last time I checked, the data has been 
modified.

Another option is to use the cache. For example, use memcached and store some
data in there. IIRC the cache is shared among all instances of Django.



That's not really solving my problem, but thanks for your input. What I 
need is a "global" python popen object from the subprocess module.


Someone helpfully suggested using a singleton for that. I really don't 
like singletons either, but this could actually be one of the few use 
cases where that would make sense, so I think that's what I'll be doing.


Kind regards,

Kasper Laudrup

--
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/6662fd12-af9f-0271-8bb7-4486e80faf90%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Django how to make user model username unique=False

2018-01-09 Thread cherngyorng
I am trying to make username unique = false as there are cases where 
username is not needed. Since i am using email address to login.
But with the django user model, how do i customise it ? 

Here is the code for my current user model:

from django.db import models
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import UserManager
from django.db.models import Q
from django.core.validators import RegexValidator


class CustomUserManager(UserManager):

def get_by_natural_key(self, username):
return self.get(
# this comment is to prevent user from using username to login
# Q(**{self.model.USERNAME_FIELD: username}) |
Q(**{self.model.EMAIL_FIELD: username})
)


class MyUser(AbstractUser):
userId = models.AutoField(primary_key=True)
gender = models.CharField(max_length=6, blank=True, null=True)
nric = models.CharField(max_length=40, blank=True, null=True)
birthday = models.DateField(blank=True, null=True)
birthTime = models.TimeField(blank=True, null=True)
ethnicGroup = models.CharField(max_length=30, blank=True, null=True)
favoriteClinic = models.CharField(max_length=50, blank=True, null=True)
appVer = models.CharField(max_length=50, blank=True, null=True)
osVer = models.CharField(max_length=50, blank=True, null=True)
mobileType = models.IntegerField(blank=True, null=True)
country_code = models.IntegerField(blank=True, null=True)
# mobile_regex = RegexValidator(regex=r'^(\+\d{1,3})?,?\s?\d{8,13}$', 
message="Phone number must not consist of space and requires country code. eg : 
+6591258565")
mobileNo = models.CharField(max_length=25, blank=True, null=True)  # 
validators should be a list
height = models.FloatField(blank=True, null=True)
weight = models.FloatField(blank=True, null=True)
bloodtype = models.CharField(max_length=3, blank=True, null=True)
allergy = models.CharField(max_length=30, blank=True, null=True)
# image1 = models.ImageField(upload_to=)
# image = models.BinaryField(editable=True, blank=True, null=True)
# displaypicture = models.ImageField
objects = CustomUserManager()

def __str__(self):
return self.username

-- 
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/81ce75ad-bada-4975-8dbc-df41de40b392%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I make a Django model from a tab-delimited data file?

2018-01-09 Thread Kasper Laudrup

Hi,

On 2018-01-09 08:09, Andréas Kühne wrote:
You will have to parse the CSV file manually with a custom management 
command (at least that is what I would do). All you need to do is open 
the file, split each row with a "," and then  import the correct columns 
to the model.


Unfortunately, CSV is a really bad, non-standardized format and simply 
splitting each row with a "," will cause you all kinds of issues with 
espacing values with a "," and other things.


I would suggest using the python CSV library for this:

https://docs.python.org/3/library/csv.html

Just though that was worth mentioning.

Kind regards,

Kasper Laudrup

--
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/83268fb2-22f6-2d6e-c14c-0015d77c48f0%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.