Re: How to create two different login system

2018-12-13 Thread Manjunath
There are multiple options to maintain different kind of users in Django.

When I came across this situation, I created a custom User class by 
inheriting AbstractBaseUser class and kept a positive integer field to 
maintain the type of user. Then I created Sub-classes Manager & Employee 
classes.
I created a custom authentication backend which will return the user object 
according to the user type.

You can try this or You can just extend the AbstractUser class.

On Friday, December 14, 2018 at 11:58:50 AM UTC+5:30, maunish dave wrote:
>
> My project contains two user one for managers and other for employees any 
> suggestions?
>

-- 
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/b3b8b178-b1bb-4a8a-9d6d-1ce3b65609fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create two different login system

2018-12-13 Thread Mike Dewhirst

On 14/12/2018 5:28 PM, maunish dave wrote:
My project contains two user one for managers and other for employees 
any suggestions?


Django contrib.auth already has groups and I use them for deciding what 
they can see vertically. Horizontally I use the ordinary relational 
mewchanisms.


Here is part of my utils.py for groups ... where 'name' is the group 
name ...


 


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
def is_author(user, name='author'):
return is_member(user, name)

def is_authority(user, name='authority'):
return is_member(user, name)

def is_consumer(user, name='consumer'):
return is_member(user, name)

def is_editor(user, name='editor'):
return is_member(user, name)

def is_manager(user, name='manager'):
return is_member(user, name)

def is_useredit(user, name='useredit'):
return is_member(user, name)
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
def is_member(user, name):
return user.is_superuser or user.groups.filter(name=name).exists()
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

 

 


--
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/CALpJ3uJ%2BOu-tiv2beHU06ZN-6PhWDAqsivDvgvKZ_RUSXDFtUQ%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/4833c678-655b-7fe3-5c63-0c6398857380%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


How to create two different login system

2018-12-13 Thread maunish dave
My project contains two user one for managers and other for employees any
suggestions?

-- 
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/CALpJ3uJ%2BOu-tiv2beHU06ZN-6PhWDAqsivDvgvKZ_RUSXDFtUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Google Plus going away - is Groups staying ?

2018-12-13 Thread Brenda Stensland
Hey - Heard that Google + is going away ... Does that include this group ? 
Anyone know ? 

Hate to see that happen!  

-- 
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/55425a7e-8dac-4855-b4f6-8bacf2877af9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems from writing test cases.

2018-12-13 Thread ANi

>
> Great! Thank you for the explanation, it's what exactly I want to know, 
>> really helps a lot. ;-)
>>
>
 

nm於 2018年12月13日星期四 UTC+8下午10時25分36秒寫道:
>
> Regarding the first question and the problem with retrieving the user with 
> `pk=1`:
> When you run your tests, Django creates a test database where all the 
> objects created by the test cases are stored, and which is destroyed after 
> all the tests are run. Each user you create gets a *new* pk. The pk number 
> is always incremented, regardless of whether the user with a previous pk 
> was deleted in the meantime or not (btw, this works the same in your 
> "regular" database, you can try adding and deleting users in the shell and 
> see yourself). So when you run both test cases and in each test case you 
> create one user, one of them gets `pk=1`, and the other `pk=2`. However, if 
> you use the `setUpTestData` method in a test case, all the objects created 
> by this methods are deleted after *this test case* finishes. This means 
> that the first test case creates a user (pk=1), then this user is deleted, 
> and the second test case creates another user (pk=2). Then you try to 
> retrieve the user with pk=1, which fails.
>
> By the way, the order in which tests are run is not always the same, so 
> you should not rely on it in your tests. Assigning created object to class 
> attributes, as you did later, is a much better approach.
>
> Hope this is what you wanted to know (;
>
>
> W dniu wtorek, 11 grudnia 2018 05:00:07 UTC+1 użytkownik ANi napisał:
>>
>> Hello,
>> I am now trying to write test cases for my project, but I find some 
>> problems.
>>
>> 1.
>>
>>
>> class FirstTest(TestCase):
>>
>> @classmethod
>> def setUpTestData(cls):
>>User.objects.create(username = 'johndoe', password = 
>> 'goodtobehere123')
>>...
>>
>> def test_case_one(self):
>>user = User.objects.get(pk=1)
>># some assertions here
>>
>>...
>>
>> class SecondTest(TestCase):
>>
>> @classmethod
>> def setUpTestData(cls):
>> User.objects.create(username = 'janedoe', password = 
>> 'nicetobethere456')
>>
>> def test_case_one(self):
>>user = User.objects.get(pk=1)
>># some assertions here
>>
>>...
>>
>>
>> If I run all the tests together, I can pass the FirstTest while getting 
>> error of "django.contrib.auth.models.DoesNotExist: User matching query does 
>> not exist." on the SecondTest.
>> If I run two test cases separately, all tests are passed.
>> Then solved it by changing it into this:
>>
>>
>> class FirstTest(TestCase):
>>
>> @classmethod
>> def setUpTestData(cls):
>> cls.user = User.objects.create(username = 'johndoe', password = 
>> 'goodtobehere123')
>> ...
>>
>> def test_case_one(self):
>>self.assertEqual(self.user.somefunc(), something)
>># some assertions here
>>
>>...
>>
>> class SecondTest(TestCase):
>>
>> @classmethod
>> def setUpTestData(cls):
>>cls.user = User.objects.create(username = 'janedoe', password = 
>> 'nicetobethere456')
>>...
>>
>> def test_case_one(self):
>>self.assertEqual(self.user.somefunc(), something)
>># some assertions here
>>
>>...
>>
>>
>>
>> However I don't know why.?
>>
>>
>> 2.
>>
>> class ViewTest(TestCase):
>>  
>> @classmethod
>> def setUpTestData(cls):
>> cls.user = User.objects.create(username = 'johndoe', password = 
>> 'goodtobehere123')
>> ...
>>
>>  def setUp(self):
>>  self.item = Item.objects.create(
>>  category = 1,
>>  item_content = 'content content',
>>  )
>>
>>
>>  def test_item_update(self):
>>  # the view will update the item and return HTTP status code 200.
>>  # if the item is not exist, raise Http404  
>>  self.c = Client() 
>>  resp = self.c.post(
>> reverse('update_item', kwargs={"pk":self.item.pk}),
>> data = {
>> "category": 2,
>> "content": "item content",
>>  }
>>  )
>>
>>  self.assertEqual(resp.status_code, 200)
>>  self.assertEqual(self.item.category, 2)
>>
>>  def test_item_delete(self):  
>>  # the view will delete the item and return HTTP status code 200.
>>  # if the item is not exist, raise Http404  
>>  self.c = Client() 
>>  resp = self.c.post(
>> reverse('delete_item'),
>> data = {
>> "pk": self.item.pk
>>  }
>>  )
>>
>>  self.assertEqual(resp.status_code, 200)
>>   
>>
>>
>>
>> I got " AssertionError: 1 != 2 ". for test_item_update()
>> and "AssertionError: 404 != 200". for test_item_delete()
>>
>> I think it is reasonable but obviously I misunderstand something. 
>>
>> Thank you. I will be very happy if you want to help me >___<
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Goog

Re: Problems from writing test cases.

2018-12-13 Thread ANi

>
> Great! Thank you for the explanation, it's what exactly I want to know, 
>> really helps a lot. ;-)
>>
>>
nm於 2018年12月13日星期四 UTC+8下午10時25分36秒寫道:
>
> Regarding the first question and the problem with retrieving the user with 
> `pk=1`:
> When you run your tests, Django creates a test database where all the 
> objects created by the test cases are stored, and which is destroyed after 
> all the tests are run. Each user you create gets a *new* pk. The pk number 
> is always incremented, regardless of whether the user with a previous pk 
> was deleted in the meantime or not (btw, this works the same in your 
> "regular" database, you can try adding and deleting users in the shell and 
> see yourself). So when you run both test cases and in each test case you 
> create one user, one of them gets `pk=1`, and the other `pk=2`. However, if 
> you use the `setUpTestData` method in a test case, all the objects created 
> by this methods are deleted after *this test case* finishes. This means 
> that the first test case creates a user (pk=1), then this user is deleted, 
> and the second test case creates another user (pk=2). Then you try to 
> retrieve the user with pk=1, which fails.
>
> By the way, the order in which tests are run is not always the same, so 
> you should not rely on it in your tests. Assigning created object to class 
> attributes, as you did later, is a much better approach.
>
> Hope this is what you wanted to know (;
>
>
> W dniu wtorek, 11 grudnia 2018 05:00:07 UTC+1 użytkownik ANi napisał:
>>
>> Hello,
>> I am now trying to write test cases for my project, but I find some 
>> problems.
>>
>> 1.
>>
>>
>> class FirstTest(TestCase):
>>
>> @classmethod
>> def setUpTestData(cls):
>>User.objects.create(username = 'johndoe', password = 
>> 'goodtobehere123')
>>...
>>
>> def test_case_one(self):
>>user = User.objects.get(pk=1)
>># some assertions here
>>
>>...
>>
>> class SecondTest(TestCase):
>>
>> @classmethod
>> def setUpTestData(cls):
>> User.objects.create(username = 'janedoe', password = 
>> 'nicetobethere456')
>>
>> def test_case_one(self):
>>user = User.objects.get(pk=1)
>># some assertions here
>>
>>...
>>
>>
>> If I run all the tests together, I can pass the FirstTest while getting 
>> error of "django.contrib.auth.models.DoesNotExist: User matching query does 
>> not exist." on the SecondTest.
>> If I run two test cases separately, all tests are passed.
>> Then solved it by changing it into this:
>>
>>
>> class FirstTest(TestCase):
>>
>> @classmethod
>> def setUpTestData(cls):
>> cls.user = User.objects.create(username = 'johndoe', password = 
>> 'goodtobehere123')
>> ...
>>
>> def test_case_one(self):
>>self.assertEqual(self.user.somefunc(), something)
>># some assertions here
>>
>>...
>>
>> class SecondTest(TestCase):
>>
>> @classmethod
>> def setUpTestData(cls):
>>cls.user = User.objects.create(username = 'janedoe', password = 
>> 'nicetobethere456')
>>...
>>
>> def test_case_one(self):
>>self.assertEqual(self.user.somefunc(), something)
>># some assertions here
>>
>>...
>>
>>
>>
>> However I don't know why.?
>>
>>
>> 2.
>>
>> class ViewTest(TestCase):
>>  
>> @classmethod
>> def setUpTestData(cls):
>> cls.user = User.objects.create(username = 'johndoe', password = 
>> 'goodtobehere123')
>> ...
>>
>>  def setUp(self):
>>  self.item = Item.objects.create(
>>  category = 1,
>>  item_content = 'content content',
>>  )
>>
>>
>>  def test_item_update(self):
>>  # the view will update the item and return HTTP status code 200.
>>  # if the item is not exist, raise Http404  
>>  self.c = Client() 
>>  resp = self.c.post(
>> reverse('update_item', kwargs={"pk":self.item.pk}),
>> data = {
>> "category": 2,
>> "content": "item content",
>>  }
>>  )
>>
>>  self.assertEqual(resp.status_code, 200)
>>  self.assertEqual(self.item.category, 2)
>>
>>  def test_item_delete(self):  
>>  # the view will delete the item and return HTTP status code 200.
>>  # if the item is not exist, raise Http404  
>>  self.c = Client() 
>>  resp = self.c.post(
>> reverse('delete_item'),
>> data = {
>> "pk": self.item.pk
>>  }
>>  )
>>
>>  self.assertEqual(resp.status_code, 200)
>>   
>>
>>
>>
>> I got " AssertionError: 1 != 2 ". for test_item_update()
>> and "AssertionError: 404 != 200". for test_item_delete()
>>
>> I think it is reasonable but obviously I misunderstand something. 
>>
>> Thank you. I will be very happy if you want to help me >___<
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google

Create an Unique Charfiled

2018-12-13 Thread Aprimus
Hi
I want to create an unique id in django charfield field:

Its better to make a sort of custom Charfiled like this:


class AutoGenerateCodeField(models.CharField):
def __init__(self, min_length=None, *args, **kwargs):
self.min_length = min_length or 4
super(AutoGenerateCodeField, self).__init__(*args, **kwargs)

def pre_save(self, model_instance, add):
if add:
attr_name = self.attname
unique_id = get_random_string(self.min_length)
look_up = {attr_name: unique_id}
count = 0
while self.model.objects.filter(**look_up).exists():
count += 1
unique_id = '{unique_id}-{count}'.format(unique_id=unique_id, 
count=count)
look_up[attr_name] = unique_id
setattr(model_instance, attr_name, unique_id)
return unique_id
return super(AutoGenerateCodeField, self).pre_save(model_instance, add)


or to override the save() method on the model field and catch the 
IntegrityError?

like this PSEUDO code:

def save(self, *args, **kwargs):
if not self.pk:
if not self.unique_id:
retries = 5
while retries > 0:
self.unique_id = get_random_string(4)
try:
with transaction.atomic():
super().save(*args, **kwargs)
except IntegrityError:
retries -= 1
   else:
break
 super().save(*args, **kwargs)



which is more efficient, django style? 

Thanks for your helps

-- 
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/35b579e9-5fd8-49f8-85bd-046be511e160%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DJANGO FOR FINANCE !

2018-12-13 Thread codesign web za

I eventually chose django-chartjs and django-datatable for this


On 13/12/2018 19:55, carlos wrote:
yes, is posible in Django make forms for input user and output make 
grahp and table


Cheers

On Thu, Dec 13, 2018 at 9:35 AM Mamoudou Diallo 
mailto:mamoudoutal...@gmail.com>> wrote:


Hey EVERYONE !

I am working on a project where I am would like to use django to
build a site that computes certain financial formulas based on
user inputs or even better (based on Time series data set) and
spits out the results in a form of a graph or predisgned table. I
have the formulas written out in python already, but I am new to
django, but I have watched a few tutorial videos and how powerful
it is. Most of the tutorials and content that I have come accross
with is primarily not related to finance but mouch more towads
building blog posts etc


Please checkout the attachement for a picture view of what I want
to do.
-- 
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/bddac915-325e-4a1c-af18-4c4b8ef39993%40googlegroups.com

.
For more options, visit https://groups.google.com/d/optout.



--
att.
Carlos Rocha
--
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/CAM-7rO2Csx2bMZBO%3DfHzSxdEwbxfkdmZFsfh4mmOnQFu1JzWGw%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/4000facf-e1cb-3aef-91cf-c33290f1bf9a%40codesign.web.za.
For more options, visit https://groups.google.com/d/optout.


Re: DJANGO FOR FINANCE !

2018-12-13 Thread carlos
yes, is posible in Django make forms for input user and output make grahp
and table

Cheers

On Thu, Dec 13, 2018 at 9:35 AM Mamoudou Diallo 
wrote:

> Hey EVERYONE !
>
> I am working on a project where I am would like to use django to build a
> site that computes certain financial formulas based on user inputs or even
> better (based on Time series data set) and spits out the results in a form
> of a graph or predisgned table. I have the formulas written out in python
> already, but I am new to django, but I have watched a few tutorial videos
> and how powerful it is. Most of the tutorials and content that I have come
> accross with is primarily not related to finance but mouch more towads
> building blog posts etc
>
>
> Please checkout the attachement for a picture view of what I want to do.
>
> --
> 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/bddac915-325e-4a1c-af18-4c4b8ef39993%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
att.
Carlos Rocha

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


Re: about unique_together

2018-12-13 Thread Peter of the Norse
Django doesn’t support multiple primary keys.  unique_together just adds an 
extra constraint to the table.

Since you didn’t specify a primary key, id was added for you by default.  

Sent from my iPad

> On Nov 14, 2018, at 1:55 AM, 胡超  wrote:
> 
> 
> class QdProjectAssist(models.Model):
> '''
> 页面推荐
> '''
> # id = models.AutoField('主键', primary_key=True)
> project_id = models.ForeignKey('QdProject', verbose_name='项目', 
> on_delete=models.CASCADE)
> assist_id = models.ForeignKey('QdAssist', verbose_name='正文', 
> on_delete=models.CASCADE)
> sort = models.PositiveIntegerField('排序', blank=True, null=True)
> addtime = models.PositiveIntegerField('添加时间')
> uptime = models.DateTimeField('更新时间', auto_now=True)
> 
> class Meta:
> managed = False
> db_table = 'qd_project_assist'
> unique_together = ('project_id', 'assist_id')
> verbose_name = '页面推荐'
> verbose_name_plural = verbose_name
> 
> I export the table with two primary keys from mysql.
> 
> Reporting errors in the course of use
> 
> django.db.utils.InternalError: (1054, "Unknown column 'qd_project_assist.id' 
> in 'field list'")
> -- 
> 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/117bd094-09bd-429c-a289-0074de2374f5%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/8E2B53CE-4BBD-4531-A7EB-AEDF6C428BAF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: python manage.py migrate failed

2018-12-13 Thread Simon Charette
It looks like you configured your CMS_CACHE_DURATIONS setting as an
integer instead of a dict with a 'content' key pointing to an integer[0].

In other words you did

CMS_CACHE_DURATIONS = 42

Instead of

CMS_CACHE_DURATIONS = {'content': 42}

Cheers,
Simon

[0] 
http://docs.django-cms.org/en/latest/reference/configuration.html#std:setting-CMS_CACHE_DURATIONS

Le jeudi 13 décembre 2018 09:25:36 UTC-5, Gilles Zoratti a écrit :
>
> Dear everyone,
> i'm new in Django cms community, 
> I had an issue with the following command "python manage.py migrate".
>
> Could it possible for you to help me on this ? 
>  
>
>> (venv) project@project-web:~/work.project.www$ python manage.py migrate
>>
>> Traceback (most recent call last):
>>
>>   File "manage.py", line 10, in 
>>
>> execute_from_command_line(sys.argv)
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py",
>>  
>>
>> line 364, in execute_from_command_line
>>
>> utility.execute()
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py",
>>  
>>
>> line 338, in execute
>>
>> django.setup()
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/django/__init__.py", 
>>
>> line 27, in setup
>>
>> apps.populate(settings.INSTALLED_APPS)
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/django/apps/registry.py",
>>  
>>
>> line 116, in populate
>>
>> app_config.ready()
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/django/contrib/admin/apps.py",
>>  
>>
>> line 23, in ready
>>
>> self.module.autodiscover()
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py",
>>  
>>
>> line 26, in autodiscover
>>
>> autodiscover_modules('admin', register_to=site)
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/django/utils/module_loading.py",
>>  
>>
>> line 50, in autodiscover_modules
>>
>> import_module('%s.%s' % (app_config.name, module_to_search))
>>
>>   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
>>
>>  
>
>> __import__(name)
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/cms/admin/__init__.py",
>>  
>>
>> line 11, in 
>>
>> plugin_pool.plugin_pool.discover_plugins()
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/cms/plugin_pool.py", 
>>
>> line 33, in discover_plugins
>>
>> invalidate_cms_page_cache()
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/cms/cache/__init__.py",
>>  
>>
>> line 69, in invalidate_cms_page_cache
>>
>> version = _get_cache_version()
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/cms/cache/__init__.py",
>>  
>>
>> line 20, in _get_cache_version
>>
>> _set_cache_version(1)
>>
>>   File 
>>
>> "/home/project/venv/local/lib/python2.7/site-packages/cms/cache/__init__.py",
>>  
>>
>> line 33, in _set_cache_version
>>
>> get_cms_setting('CACHE_DURATIONS')['content']
>>
>> TypeError: 'int' object has no attribute '__getitem__'
>>
>> (venv) project@project-web:~/work.medor.www$
>>
>>
>
> In advance Thank So Much 
>

-- 
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/e04a0811-1f80-49f8-a796-07e98927b0cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


pyhton manage.py migrate not working

2018-12-13 Thread Gilles Zoratti


Dear every one,
i'm new in the Django cms environment, and I need your help ! ( please :) )

When I tried to "install" the cms is not working, I had a long list of 
error message

(venv) project@project-web:~/work.project.www$ python manage.py migrate 

Traceback (most recent call last): File "manage.py", line 10, in 
execute_from_command_line(sys.argv) File 
"/home/project/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py",
 
line 364, in execute_from_command_line utility.execute() File 
"/home/project/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py",
 
line 338, in execute django.setup() File 
"/home/project/venv/local/lib/python2.7/site-packages/django/__init__.py", 
line 27, in setup apps.populate(settings.INSTALLED_APPS) File 
"/home/project/venv/local/lib/python2.7/site-packages/django/apps/registry.py", 
line 116, in populate app_config.ready() File 
"/home/project/venv/local/lib/python2.7/site-packages/django/contrib/admin/apps.py",
 
line 23, in ready self.module.autodiscover() File 
"/home/project/venv/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py",
 
line 26, in autodiscover autodiscover_modules('admin', register_to=site) 
File 
"/home/project/venv/local/lib/python2.7/site-packages/django/utils/module_loading.py",
 
line 50, in autodiscover_modules import_module('%s.%s' % (app_config.name, 
module_to_search)) File "/usr/lib/python2.7/importlib/__init__.py", line 
37, in import_module __import__(name) File 
"/home/project/venv/local/lib/python2.7/site-packages/cms/admin/__init__.py", 
line 11, in plugin_pool.plugin_pool.discover_plugins() File 
"/home/project/venv/local/lib/python2.7/site-packages/cms/plugin_pool.py", 
line 33, in discover_plugins invalidate_cms_page_cache() File 
"/home/project/venv/local/lib/python2.7/site-packages/cms/cache/__init__.py", 
line 69, in invalidate_cms_page_cache version = _get_cache_version() File 
"/home/project/venv/local/lib/python2.7/site-packages/cms/cache/__init__.py", 
line 20, in _get_cache_version _set_cache_version(1) File 
"/home/project/venv/local/lib/python2.7/site-packages/cms/cache/__init__.py", 
line 33, in _set_cache_version 
get_cms_setting('CACHE_DURATIONS')['content'] TypeError: 'int' object has 
no attribute '__getitem__' (venv) project@project-web:~/work.project.www$ 

OS: Ubuntu / Debian
Version of python: 2.7

In advance ,
Thank's so much

-- 
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/1b0334a6-d7ba-4401-804f-f25ff7e6d7ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


channels layers connect with aws ec2

2018-12-13 Thread rajpootsuryasingh
How to connect *CHANNEL_LAYERS* config host on AWS ec2 ?

 CHANNEL_LAYERS = {
 'default': {
 'BACKEND': 'channels_redis.core.RedisChannelLayer',
 'CONFIG': {
 "hosts":[("", 6379)],
 },
 },
  }


I am trying like this.
please help me.
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/6cf5b9a5-1a1f-4721-9b13-a418b925d56d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Multipleselect

2018-12-13 Thread Anas P H
I've used CheckboxSelectMultiple  one field in my view.It shows up fine in 
the browser, but on submit I receive the "Select a valid . That choice is 
not one of the available choices."  but i selected already. anybody please 
help.

-- 
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/7be7ce23-17f0-4d7e-ab03-c9131200b75e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems from writing test cases.

2018-12-13 Thread nm
Regarding the first question and the problem with retrieving the user with 
`pk=1`:
When you run your tests, Django creates a test database where all the 
objects created by the test cases are stored, and which is destroyed after 
all the tests are run. Each user you create gets a *new* pk. The pk number 
is always incremented, regardless of whether the user with a previous pk 
was deleted in the meantime or not (btw, this works the same in your 
"regular" database, you can try adding and deleting users in the shell and 
see yourself). So when you run both test cases and in each test case you 
create one user, one of them gets `pk=1`, and the other `pk=2`. However, if 
you use the `setUpTestData` method in a test case, all the objects created 
by this methods are deleted after *this test case* finishes. This means 
that the first test case creates a user (pk=1), then this user is deleted, 
and the second test case creates another user (pk=2). Then you try to 
retrieve the user with pk=1, which fails.

By the way, the order in which tests are run is not always the same, so you 
should not rely on it in your tests. Assigning created object to class 
attributes, as you did later, is a much better approach.

Hope this is what you wanted to know (;


W dniu wtorek, 11 grudnia 2018 05:00:07 UTC+1 użytkownik ANi napisał:
>
> Hello,
> I am now trying to write test cases for my project, but I find some 
> problems.
>
> 1.
>
>
> class FirstTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
>User.objects.create(username = 'johndoe', password = 
> 'goodtobehere123')
>...
>
> def test_case_one(self):
>user = User.objects.get(pk=1)
># some assertions here
>
>...
>
> class SecondTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
> User.objects.create(username = 'janedoe', password = 
> 'nicetobethere456')
>
> def test_case_one(self):
>user = User.objects.get(pk=1)
># some assertions here
>
>...
>
>
> If I run all the tests together, I can pass the FirstTest while getting 
> error of "django.contrib.auth.models.DoesNotExist: User matching query does 
> not exist." on the SecondTest.
> If I run two test cases separately, all tests are passed.
> Then solved it by changing it into this:
>
>
> class FirstTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
> cls.user = User.objects.create(username = 'johndoe', password = 
> 'goodtobehere123')
> ...
>
> def test_case_one(self):
>self.assertEqual(self.user.somefunc(), something)
># some assertions here
>
>...
>
> class SecondTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
>cls.user = User.objects.create(username = 'janedoe', password = 
> 'nicetobethere456')
>...
>
> def test_case_one(self):
>self.assertEqual(self.user.somefunc(), something)
># some assertions here
>
>...
>
>
>
> However I don't know why.?
>
>
> 2.
>
> class ViewTest(TestCase):
>  
> @classmethod
> def setUpTestData(cls):
> cls.user = User.objects.create(username = 'johndoe', password = 
> 'goodtobehere123')
> ...
>
>  def setUp(self):
>  self.item = Item.objects.create(
>  category = 1,
>  item_content = 'content content',
>  )
>
>
>  def test_item_update(self):
>  # the view will update the item and return HTTP status code 200.
>  # if the item is not exist, raise Http404  
>  self.c = Client() 
>  resp = self.c.post(
> reverse('update_item', kwargs={"pk":self.item.pk}),
> data = {
> "category": 2,
> "content": "item content",
>  }
>  )
>
>  self.assertEqual(resp.status_code, 200)
>  self.assertEqual(self.item.category, 2)
>
>  def test_item_delete(self):  
>  # the view will delete the item and return HTTP status code 200.
>  # if the item is not exist, raise Http404  
>  self.c = Client() 
>  resp = self.c.post(
> reverse('delete_item'),
> data = {
> "pk": self.item.pk
>  }
>  )
>
>  self.assertEqual(resp.status_code, 200)
>   
>
>
>
> I got " AssertionError: 1 != 2 ". for test_item_update()
> and "AssertionError: 404 != 200". for test_item_delete()
>
> I think it is reasonable but obviously I misunderstand something. 
>
> Thank you. I will be very happy if you want to help 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 vis

Issue with model method (Solved)

2018-12-13 Thread Felix Lazaro Carbonell
I beg your pardon. 

It was my mistake in a functional test. I missed part of the data needed to 
make it work correctly.

 

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+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/009301d492e7%24c3837520%244a8a5f60%24%40epepm.cupet.cu.
For more options, visit https://groups.google.com/d/optout.


Re: How to send parameters to templates and adjust the page url by path?

2018-12-13 Thread Saeed Pooladzadeh
Thank you Ira

در چهارشنبه 12 دسامبر 2018، ساعت 19:21:26 (UTC-8)، lingo...@gmail.com نوشته:
>
> Hello,
>
> How to send parameters to templates and adjust the page url by path?
>
> regards, 
>
> Saeed
>

-- 
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/0ccb8f35-324f-4bb1-8aa2-00878607768f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with data bound ModelChoiceField

2018-12-13 Thread Glen D souza
In the First Screenshot the code is
def __str__(self):
return "Customer" + "self.id"



Remove the quotes from "self.id"

def __str__(self):
return "Customer" + self.id



On Wed, 12 Dec 2018 at 10:47,  wrote:

>
> TY madjardi for all your input! I continued to search and found what I
> wanted. But I still need to understand how it all works. I know it is an
> initiation function on the form but not sure how variables are transported
> around to give me the results. But I think I can dig further to find out.
> Here is what works for me:
> class frmCustomerList(forms.Form):
> name = forms.ChoiceField(choices = [])
>
> def __init__(self, *args, **kwargs):
> super(frmCustomerList, self).__init__(*args, **kwargs)
> self.fields['name'].choices = [(x.pk, x.name) for x in
> dbCustomer.objects.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+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/1f80363b-47e4-490f-88e5-3c52277ea615%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/CAHfehoXM53KRQhEeviZdZ4O_aa5gNLZ9aceWZtPySiTQO%2BAuNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.