Re: Unable to set up celery in supervisord

2016-07-21 Thread George Silva
If you are getting variables from the environment, supervisor that special
environment directive. The variables need to specified in the supervisor
conf file, such as:

command=/home/ankush/jremind/env/bin/celery --app=remind.celery:app worker
--loglevel=INFO
environment=PYTHONPATH=/home/ankush/jremind/jremind,
*SECRET_KEY="foo",VARIABLE_A="a"*
directory=/home/ankush/jremind/jremind
stdout_logfile=/home/ankush/jremind/logs/celeryd.log
stderr_logfile=/home/ankush/jremind/logs/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=600

Supervisor won't be able to read them otherwise. There are other
alternatives, for example, if you are using a crafted command, using bash:

command=/home/foo/command.sh
environment=PYTHONPATH=/home/ankush/jremind/jremind
directory=/home/ankush/jremind/jremind
stdout_logfile=/home/ankush/jremind/logs/celeryd.log
stderr_logfile=/home/ankush/jremind/logs/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=600


command.sh

!#/bin/bash

export SECRET_KEY="foo"
export VARIABLE_A="a"

echo $SECRET_KEY
echo $VARIABLE_A


-- 
George R. C. Silva
Sigma Geosistemas LTDA

http://www.sigmageosistemas.com.br/

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


Unable to set up celery in supervisord

2016-07-21 Thread Ankush Thakur
​I'm trying to set up celery as a supervisord job (for my Django project)
and getting an error. Most likely it's because of wrong import paths (or
some other environment setting), but I have no idea what. Please help!

Here's my directory structure ('>' means down one level):

/home/ankush/jremind
>env
>jremind
>>celerybeat.pid
>>celerybeat-schedule
>>jremind
>>manage.py
>>remind
>>requirements.txt
>logs

The supervisord conf file is:​

command=/home/ankush/jremind/env/bin/celery --app=remind.celery:app worker
--loglevel=INFO
environment=PYTHONPATH=/home/ankush/jremind/jremind
directory=/home/ankush/jremind/jremind
stdout_logfile=/home/ankush/jremind/logs/celeryd.log
stderr_logfile=/home/ankush/jremind/logs/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=600

Now, when I try to start the process, it exists too quickly, and I'm left
with the following in the logs:

. . .
self._conf = force_mapping(obj)
  File
"/home/ankush/jremind/env/lib/python3.4/site-packages/celery/datastructures.py",
line 50, in force_mapping
if isinstance(m, (LazyObject, LazySettings)):
  File
"/home/ankush/jremind/env/lib/python3.4/site-packages/django/utils/functional.py",
line 204, in inner
self._setup()
  File
"/home/ankush/jremind/env/lib/python3.4/site-packages/django/conf/__init__.py",
line 43, in _setup
self._wrapped = Settings(settings_module)
  File
"/home/ankush/jremind/env/lib/python3.4/site-packages/django/conf/__init__.py",
line 120, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must
not be empty.

I'm not sure why I'm getting this error, because the secret key is most
definitely there and the app runs fine. What am I doing wrong?

Best,
Ankush​

-- 
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/CALX%3DrKLVqMePZnsZ5SGRb4bqoyahAQOBbheWshH%2B5PXGdnQw%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.8.13 saving new user gets error NOT NULL constraint failed: auth_user.last_login

2016-07-21 Thread bobhaugen
Hah! You are right! My fault.

On Thursday, July 21, 2016 at 11:55:29 AM UTC-5, Simon Charette wrote:
>
> If you upgraded from Django 1.7 you should make sure to run all auth 
> migrations.
>
> If you're using a custom user model make sure to makemigrations for its 
> app and proceed to migrate it.
>
> Simon
>
> Le jeudi 21 juillet 2016 11:46:37 UTC-4, bobhaugen a écrit :
>>
>> NOT NULL constraint failed: auth_user.last_login
>>>
>>>
>>>
>> This is a new user. Why should it have a last_login value? 
>>
>> I coded around it by giving the new user a fictitious last_login value, 
>> but still...
>>
>

-- 
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/2866e047-43e6-4801-86a7-e5cbb2a115d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.8.13 saving new user gets error NOT NULL constraint failed: auth_user.last_login

2016-07-21 Thread Simon Charette
If you upgraded from Django 1.7 you should make sure to run all auth 
migrations.

If you're using a custom user model make sure to makemigrations for its app 
and proceed to migrate it.

Simon

Le jeudi 21 juillet 2016 11:46:37 UTC-4, bobhaugen a écrit :
>
> NOT NULL constraint failed: auth_user.last_login
>>
>>
>>
> This is a new user. Why should it have a last_login value? 
>
> I coded around it by giving the new user a fictitious last_login value, 
> but still...
>

-- 
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/a7406d2a-38f0-4b07-b325-570925ab03cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 1.8.13 saving new user gets error NOT NULL constraint failed: auth_user.last_login

2016-07-21 Thread bobhaugen

>
> NOT NULL constraint failed: auth_user.last_login
>
>
>
This is a new user. Why should it have a last_login value? 

I coded around it by giving the new user a fictitious last_login value, but 
still...

-- 
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/10b0a641-0557-4602-954c-95892b526be2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Question has mediated relation to the Django.

2016-07-21 Thread Seti Volkylany
How get a total count pages in PDF file, created with using ReportLab, 
without third-party apps and hardcode (or violation DRY)?

-- 
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/4540d18a-3164-4082-b1fd-209728f3e935%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Email Model

2016-07-21 Thread ludovic coues
https://docs.djangoproject.com/en/1.9/topics/db/examples/many_to_many/

Each student can subscribe to more than one newsletter
Each newsletter have many of students.




2016-07-21 15:20 GMT+02:00 Ant :
> Being a Django "newcomer" I am hoping someone can help us with this simple
> problem.
>
> We have a model for students containing names and email addresses. We want
> them to subscribe to various newsletters.
>
> Is it better to have a separate model for newsletters and how would we
> produce the list for these subscribers.
>
> I have read other posts on this subject but am still somewhat confused!
>
> Any help would be greatly appreciated.
>
> 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/6c79fe60-559b-47cd-9613-168262edf517%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

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


Re: How make testing for a generated PDF file?

2016-07-21 Thread Avraham Serour
input -> function == expected output

On Thu, Jul 21, 2016 at 4:37 PM, Seti Volkylany 
wrote:

>
>
> --
> 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/67893cdf-0f0c-46c2-8d66-b7123dcf1836%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/CAFWa6tK%2Bhc47v97-kJGxFx%3D%3DZELmfvaHZX_uGDUrNkZd4PTvBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How make testing for a generated PDF file?

2016-07-21 Thread Seti Volkylany
 

-- 
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/67893cdf-0f0c-46c2-8d66-b7123dcf1836%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Foreign Key

2016-07-21 Thread 'David Turner' via Django users
Okay thanks for the clarification

On 21 July 2016 at 14:13, ludovic coues  wrote:

> I was thinking of the case of one model which can have a foreign key
> to one of two models.
> Like a title model that can have a foreign key to a page model or an
> article model.
>
> 2016-07-21 13:15 GMT+02:00 'David Turner' via Django users
> :
> > Hi
> >
> > Thanks for this.
> > So basically if I am using the county Foreign key in a few different
> models
> > I am fine. I am not sure what you meant by this
> > "as long as no models can link to notes or counties and
> > not both, simple foreign key are fine."
> >
> >
> > On 21 July 2016 at 11:13, ludovic coues  wrote:
> >>
> >> Generic Foreign Key solve a very specific problem. Foreign key to
> >> arbitrary models. Like a tagging system, with the ability to set a tag
> >> to user, article, comment, media in a blog.
> >>
> >> For your use, as long as no models can link to notes or counties and
> >> not both, simple foreign key are fine.
> >> And even then, it might be easier to have a foreign key to both and
> >> maybe a method on your models to return one without testing which one
> >> is None.
> >>
> >> Generic Foreign Key have some non-trivial drawback. For exemple, you
> >> can't use them in a filter on a queryset.
> >>
> >> 2016-07-21 9:43 GMT+02:00 'dtdave' via Django users
> >> :
> >> > I have two models notes and counties which are used across multiple
> >> > models.
> >> > At the moment the realtionship is done using a foreign key.
> >> >
> >> > I am getting conflicting advice on whether to use a Generic Foreign
> Key.
> >> > Could someone please enlighen me as to the best practice?
> >> >
> >> > Many thanks in advance
> >> >
> >> > --
> >> > 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/37577063-87bf-4460-a6fb-7a17d74dc79c%40googlegroups.com
> .
> >> > For more options, visit https://groups.google.com/d/optout.
> >>
> >>
> >>
> >> --
> >>
> >> Cordialement, Coues Ludovic
> >> +336 148 743 42
> >>
> >> --
> >> You received this message because you are subscribed to a topic in the
> >> Google Groups "Django users" group.
> >> To unsubscribe from this topic, visit
> >> https://groups.google.com/d/topic/django-users/MAoN1LNDMEg/unsubscribe.
> >> To unsubscribe from this group and all its topics, 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/CAEuG%2BTZJG5Vi6OD9hpzcfVnEO0dkw4-3a4KF8hdPtK5O1oASow%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 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/CALwQ%2B-ueLUWTc6taeQAES-krh_ibH4ZfnFLufc6R6OwDz1oOwA%40mail.gmail.com
> .
> >
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/MAoN1LNDMEg/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAEuG%2BTZeXjDPF7hqefi%3DJG3kadckdLzF_1oX0T3zDCLMwQQk3w%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 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 

Django Email Model

2016-07-21 Thread Ant
Being a Django "newcomer" I am hoping someone can help us with this simple 
problem.

We have a model for students containing names and email addresses. We want 
them to subscribe to various newsletters. 

Is it better to have a separate model for newsletters and how would we 
produce the list for these subscribers.

I have read other posts on this subject but am still somewhat confused!

Any help would be greatly appreciated.

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/6c79fe60-559b-47cd-9613-168262edf517%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Foreign Key

2016-07-21 Thread ludovic coues
I was thinking of the case of one model which can have a foreign key
to one of two models.
Like a title model that can have a foreign key to a page model or an
article model.

2016-07-21 13:15 GMT+02:00 'David Turner' via Django users
:
> Hi
>
> Thanks for this.
> So basically if I am using the county Foreign key in a few different models
> I am fine. I am not sure what you meant by this
> "as long as no models can link to notes or counties and
> not both, simple foreign key are fine."
>
>
> On 21 July 2016 at 11:13, ludovic coues  wrote:
>>
>> Generic Foreign Key solve a very specific problem. Foreign key to
>> arbitrary models. Like a tagging system, with the ability to set a tag
>> to user, article, comment, media in a blog.
>>
>> For your use, as long as no models can link to notes or counties and
>> not both, simple foreign key are fine.
>> And even then, it might be easier to have a foreign key to both and
>> maybe a method on your models to return one without testing which one
>> is None.
>>
>> Generic Foreign Key have some non-trivial drawback. For exemple, you
>> can't use them in a filter on a queryset.
>>
>> 2016-07-21 9:43 GMT+02:00 'dtdave' via Django users
>> :
>> > I have two models notes and counties which are used across multiple
>> > models.
>> > At the moment the realtionship is done using a foreign key.
>> >
>> > I am getting conflicting advice on whether to use a Generic Foreign Key.
>> > Could someone please enlighen me as to the best practice?
>> >
>> > Many thanks in advance
>> >
>> > --
>> > 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/37577063-87bf-4460-a6fb-7a17d74dc79c%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/MAoN1LNDMEg/unsubscribe.
>> To unsubscribe from this group and all its topics, 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/CAEuG%2BTZJG5Vi6OD9hpzcfVnEO0dkw4-3a4KF8hdPtK5O1oASow%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 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/CALwQ%2B-ueLUWTc6taeQAES-krh_ibH4ZfnFLufc6R6OwDz1oOwA%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

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


Can i use groups permissions with custom user model?

2016-07-21 Thread Max M
Hello!
For example, i extend User:

class ExtUserManager(BaseUserManager):
def create_user(self, email, password=None):
"""
Creates and saves a User with the given email, date of
birth and password.
"""
if not email:
raise ValueError('Users must have an email address')

user = self.model(
email=self.normalize_email(email),
)

user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, password):
"""
Creates and saves a superuser with the given email, date of
birth and password.
"""
user = self.create_user(
email=self.normalize_email(email),
password=password,
)
user.is_admin = True
user.is_active = True
user.is_staff = True
user.save(using=self._db)
return user


class ExtUser(AbstractBaseUser, PermissionsMixin):
first_name = models.CharField(max_length=50, blank=False, null=True, 
verbose_name='First Name')
last_name = models.CharField(max_length=50, blank=False, null=True, 
verbose_name='Family Name')
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
phone = models.CharField(max_length=50, blank=False, null=True, 
verbose_name='Phone Number')
company = models.ForeignKey(Company, null=True, blank=True, 
verbose_name='Company')
is_active = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
objects = ExtUserManager()

USERNAME_FIELD = 'email'

def get_full_name(self):
# The user is identified by their email address
return self.email

def get_short_name(self):
# The user is identified by their email address
return self.email

def __str__(self):  # __unicode__ on Python 2
return self.email

def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True

def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True

@property
def is_employee(self):
return bool(self.groups.filter(name='Employee').count())

@property
def is_restaurant(self):
return bool(self.groups.filter(name='Restaurant').count())

class Meta:
verbose_name = 'User'


And i create group "Employee" with some minimal privileges. After this, i add 
user to this group, but user have all admin privileges. What's wrong?

-- 
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/21329493-34ed-4124-abd2-cc58b7807f69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Can i use group permissions with custom User model?

2016-07-21 Thread Max M
Hello everyone! 
For example, i have an extended User model:

class ExtUserManager(BaseUserManager):
def create_user(self, email, password=None):
"""
Creates and saves a User with the given email, date of
birth and password.
"""
if not email:
raise ValueError('Users must have an email address')

user = self.model(
email=self.normalize_email(email),
)

user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, password):
"""
Creates and saves a superuser with the given email, date of
birth and password.
"""
user = self.create_user(
email=self.normalize_email(email),
password=password,
)
user.is_admin = True
user.is_active = True
user.is_staff = True
user.save(using=self._db)
return user


class ExtUser(AbstractBaseUser, PermissionsMixin):
first_name = models.CharField(max_length=50, blank=False, null=True, 
verbose_name='First Name')
last_name = models.CharField(max_length=50, blank=False, null=True, 
verbose_name='Family Name')
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
phone = models.CharField(max_length=50, blank=False, null=True, 
verbose_name='Phone Number')
company = models.ForeignKey(Company, null=True, blank=True, 
verbose_name='Company')
is_active = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
objects = ExtUserManager()

USERNAME_FIELD = 'email'

def get_full_name(self):
# The user is identified by their email address
return self.email

def get_short_name(self):
# The user is identified by their email address
return self.email

def __str__(self):  # __unicode__ on Python 2
return self.email

def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True

def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True

@property
def is_employee(self):
return bool(self.groups.filter(name='Employee').count())

@property
def is_restaurant(self):
return bool(self.groups.filter(name='Restaurant').count())

class Meta:
verbose_name = 'User'


Also, i create group "Employee" and give minimal permissions for that group. 
After this, i create user and add him to that group (Employee), but user (not 
admin) have all admin privileges. What i do wrong?

-- 
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/b24b77db-6672-45bb-aea5-ca143c8108d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to share a DB between Django and another application

2016-07-21 Thread Fred Stluka

  
  
Albert,

Yes, any other app , written in Python or any other language, should
be able to access your relational DB concurrently with your Django 
app, if it has the right credentials.  This is true for PostgreSQL,

MySQL, Oracle, DB2, or any other RDBMS you might use.

--Fred
  
  
  Fred Stluka -- mailto:f...@bristle.com --
  http://bristle.com/~fred/
  
  Bristle Software, Inc -- http://bristle.com -- Glad to be of
  service!
  
  Open Source: Without walls and fences, we need no Windows or
  Gates.
  
  

On 7/20/16 11:03 AM, Albert180 wrote:


  Hello I wanted to know if it's possible to share a
Database between a Django App ( The WebApp) and another external
App which processes the Data ?
  -- 
  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/5b863fe3-c99f-44cf-b3fa-1773911a2223%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/a0454491-752b-3daf-65cc-d9950ef45751%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Foreign Key

2016-07-21 Thread 'David Turner' via Django users
Hi

Thanks for this.
So basically if I am using the county Foreign key in a few different models
I am fine. I am not sure what you meant by this
"as long as no models can link to notes or counties and
not both, simple foreign key are fine."


On 21 July 2016 at 11:13, ludovic coues  wrote:

> Generic Foreign Key solve a very specific problem. Foreign key to
> arbitrary models. Like a tagging system, with the ability to set a tag
> to user, article, comment, media in a blog.
>
> For your use, as long as no models can link to notes or counties and
> not both, simple foreign key are fine.
> And even then, it might be easier to have a foreign key to both and
> maybe a method on your models to return one without testing which one
> is None.
>
> Generic Foreign Key have some non-trivial drawback. For exemple, you
> can't use them in a filter on a queryset.
>
> 2016-07-21 9:43 GMT+02:00 'dtdave' via Django users
> :
> > I have two models notes and counties which are used across multiple
> models.
> > At the moment the realtionship is done using a foreign key.
> >
> > I am getting conflicting advice on whether to use a Generic Foreign Key.
> > Could someone please enlighen me as to the best practice?
> >
> > Many thanks in advance
> >
> > --
> > 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/37577063-87bf-4460-a6fb-7a17d74dc79c%40googlegroups.com
> .
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/MAoN1LNDMEg/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAEuG%2BTZJG5Vi6OD9hpzcfVnEO0dkw4-3a4KF8hdPtK5O1oASow%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 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/CALwQ%2B-ueLUWTc6taeQAES-krh_ibH4ZfnFLufc6R6OwDz1oOwA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generic Foreign Key

2016-07-21 Thread ludovic coues
Generic Foreign Key solve a very specific problem. Foreign key to
arbitrary models. Like a tagging system, with the ability to set a tag
to user, article, comment, media in a blog.

For your use, as long as no models can link to notes or counties and
not both, simple foreign key are fine.
And even then, it might be easier to have a foreign key to both and
maybe a method on your models to return one without testing which one
is None.

Generic Foreign Key have some non-trivial drawback. For exemple, you
can't use them in a filter on a queryset.

2016-07-21 9:43 GMT+02:00 'dtdave' via Django users
:
> I have two models notes and counties which are used across multiple models.
> At the moment the realtionship is done using a foreign key.
>
> I am getting conflicting advice on whether to use a Generic Foreign Key.
> Could someone please enlighen me as to the best practice?
>
> Many thanks in advance
>
> --
> 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/37577063-87bf-4460-a6fb-7a17d74dc79c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

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


Generic Foreign Key

2016-07-21 Thread 'dtdave' via Django users
I have two models notes and counties which are used across multiple models. 
At the moment the realtionship is done using a foreign key.

I am getting conflicting advice on whether to use a Generic Foreign Key. 
Could someone please enlighen me as to the best practice?

Many thanks in advance

-- 
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/37577063-87bf-4460-a6fb-7a17d74dc79c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.