Re: Django phone number validation

2017-06-21 Thread Andréas Kühne
Hi,

https://github.com/stefanfoulis/django-phonenumber-field

You could probably use that library - it works against googles phonenumber
library, which is the library that is used on andoid phones as well.

Regards,

Andréas

2017-06-21 8:18 GMT+02:00 Santosh Yelamarthi :

> Hi All,
>
> Can anyone please share how to validate phone number in django.
>
> 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/ff21c0e2-e2c5-47e9-b844-b436c87e616d%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/CAK4qSCe%2BCAQOzeh6iD49HnETvNkh%2Bc_DNd35usr0-w1tjNkOCg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


User Based role in Django

2017-06-21 Thread Mannu Gupta
I want to make a role based user in Django like the following :- 

User with Subscription level 0 will have some feature and some basic fields 
like first name , last name etc. 
User with Subscription level 1 will have some more feature and some extra 
fields  like tax-id , national id , nationality, is_disable etc . 
User with Subscription level 2 will have more features with all the fields 
with the fields with same as fields of Subscription level 1 since he has 
already subscribed only he is upgrading.
User with Subscription level 3 will have more feature with all the fields 
with the fields same above .

How do i make the user model and related this relate to its role , and how 
do i be able to set permission for different user ?

-- 
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/4bdc5c54-5c90-4515-b977-30fcb612b3ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: User Based role in Django

2017-06-21 Thread Jani Tiainen
Hi,

We have been using user groups for that. And then we check and filter out
based on given group(s).

21.6.2017 10.45 "Mannu Gupta"  kirjoitti:

> I want to make a role based user in Django like the following :-
>
> User with Subscription level 0 will have some feature and some basic
> fields like first name , last name etc.
> User with Subscription level 1 will have some more feature and some extra
> fields  like tax-id , national id , nationality, is_disable etc .
> User with Subscription level 2 will have more features with all the fields
> with the fields with same as fields of Subscription level 1 since he has
> already subscribed only he is upgrading.
> User with Subscription level 3 will have more feature with all the fields
> with the fields same above .
>
> How do i make the user model and related this relate to its role , and how
> do i be able to set permission for different user ?
>
> --
> 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/4bdc5c54-5c90-4515-b977-30fcb612b3ff%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/CAHn91od9D9aeoigGQ4aN3NKX_woJn%2BENPrePMg%2BKEKhZBb-W9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: User Based role in Django

2017-06-21 Thread Mannu Gupta
Hi ,
Will I be able to trace if user upgrde the subscription level ?

Manni

On Wed, Jun 21, 2017 at 1:41 PM, Jani Tiainen  wrote:

> Hi,
>
> We have been using user groups for that. And then we check and filter out
> based on given group(s).
>
> 21.6.2017 10.45 "Mannu Gupta"  kirjoitti:
>
>> I want to make a role based user in Django like the following :-
>>
>> User with Subscription level 0 will have some feature and some basic
>> fields like first name , last name etc.
>> User with Subscription level 1 will have some more feature and some extra
>> fields  like tax-id , national id , nationality, is_disable etc .
>> User with Subscription level 2 will have more features with all the
>> fields with the fields with same as fields of Subscription level 1 since he
>> has already subscribed only he is upgrading.
>> User with Subscription level 3 will have more feature with all the fields
>> with the fields same above .
>>
>> How do i make the user model and related this relate to its role , and
>> how do i be able to set permission for different user ?
>>
>> --
>> 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/4bdc5c54-5c90-4515-b977-30fcb612b3ff%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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/2JjuGF1-4PU/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/CAHn91od9D9aeoigGQ4aN3NKX_
> woJn%2BENPrePMg%2BKEKhZBb-W9Q%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/CAEDhgmi-cONKSHSBBJOJu6JKPy42-n4zfDY%2BeUmOQyMXm1bj-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: User Based role in Django

2017-06-21 Thread Jani Tiainen
Well its your code, so yes if you write code that does it.

It doesn't happen magically for you.

21.6.2017 11.15 "Mannu Gupta"  kirjoitti:

> Hi ,
> Will I be able to trace if user upgrde the subscription level ?
>
> Manni
>
> On Wed, Jun 21, 2017 at 1:41 PM, Jani Tiainen  wrote:
>
>> Hi,
>>
>> We have been using user groups for that. And then we check and filter out
>> based on given group(s).
>>
>> 21.6.2017 10.45 "Mannu Gupta"  kirjoitti:
>>
>>> I want to make a role based user in Django like the following :-
>>>
>>> User with Subscription level 0 will have some feature and some basic
>>> fields like first name , last name etc.
>>> User with Subscription level 1 will have some more feature and some
>>> extra fields  like tax-id , national id , nationality, is_disable etc .
>>> User with Subscription level 2 will have more features with all the
>>> fields with the fields with same as fields of Subscription level 1 since he
>>> has already subscribed only he is upgrading.
>>> User with Subscription level 3 will have more feature with all the
>>> fields with the fields same above .
>>>
>>> How do i make the user model and related this relate to its role , and
>>> how do i be able to set permission for different user ?
>>>
>>> --
>>> 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/4bdc5c54-5c90-4515-b977-30fcb612b3ff%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> 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/to
>> pic/django-users/2JjuGF1-4PU/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/ms
>> gid/django-users/CAHn91od9D9aeoigGQ4aN3NKX_woJn%2BENPrePMg%
>> 2BKEKhZBb-W9Q%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/CAEDhgmi-cONKSHSBBJOJu6JKPy42-n4zfDY%
> 2BeUmOQyMXm1bj-A%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/CAHn91oeKBtiVdkJj6JFd4_qbX98%2B0vvbonKc%2BJVdtcb0akJ81w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: User Based role in Django

2017-06-21 Thread Mannu Gupta
I meant that using your method i.e by making different groups .
When he upgrade the group .
How about making another table having user, his subscription level and
changed_at field(which traces when he /upgrade the group )

Just want to know your suggestion .

Mannu

On Jun 21, 2017 1:48 PM, "Jani Tiainen"  wrote:

> Well its your code, so yes if you write code that does it.
>
> It doesn't happen magically for you.
>
> 21.6.2017 11.15 "Mannu Gupta"  kirjoitti:
>
>> Hi ,
>> Will I be able to trace if user upgrde the subscription level ?
>>
>> Manni
>>
>> On Wed, Jun 21, 2017 at 1:41 PM, Jani Tiainen  wrote:
>>
>>> Hi,
>>>
>>> We have been using user groups for that. And then we check and filter
>>> out based on given group(s).
>>>
>>> 21.6.2017 10.45 "Mannu Gupta"  kirjoitti:
>>>
 I want to make a role based user in Django like the following :-

 User with Subscription level 0 will have some feature and some basic
 fields like first name , last name etc.
 User with Subscription level 1 will have some more feature and some
 extra fields  like tax-id , national id , nationality, is_disable etc .
 User with Subscription level 2 will have more features with all the
 fields with the fields with same as fields of Subscription level 1 since he
 has already subscribed only he is upgrading.
 User with Subscription level 3 will have more feature with all the
 fields with the fields same above .

 How do i make the user model and related this relate to its role , and
 how do i be able to set permission for different user ?

 --
 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/4bdc5c54-5c90-4515-b977-30fcb612b3ff%40goog
 legroups.com
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>> --
>>> 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/to
>>> pic/django-users/2JjuGF1-4PU/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/ms
>>> gid/django-users/CAHn91od9D9aeoigGQ4aN3NKX_woJn%2BENPrePMg%2
>>> BKEKhZBb-W9Q%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/ms
>> gid/django-users/CAEDhgmi-cONKSHSBBJOJu6JKPy42-n4zfDY%2BeUmO
>> QyMXm1bj-A%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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/2JjuGF1-4PU/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/CAHn91oeKBtiVdkJj6JFd4_qbX98%
> 2B0vvbonKc%2BJVdtcb0akJ81w%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are 

Re: url patterns question

2017-06-21 Thread Melvyn Sopacua
On Tuesday 20 June 2017 18:08:02 James Schneider wrote:

> > And his problem is that it does *not* match. Not that it does.
> 
> And for that I think my statement still stands that Django is
> stripping the last portion of the URL as a GET argument. I'm betting
> that
> requests.GET.get('abc') will return '12/' per the last example from
> the OP.

Yes, but for the first problem, r'^blank/.*$' should match blank/abc and 
generates a 
404. I think the matching isn't the problem and the 404 is caused either by 
ordering 
issue in urlpatterns (first match wins, no others are tried) or with the view 
itself 
(get_object_or_404).

You are correct that urlpatterns are only matched against request.path. This 
excludes the query string.

-- 
Melvyn Sopacua

-- 
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/1645447.02AZaXVTC8%40devstation.
For more options, visit https://groups.google.com/d/optout.


Django Import/Export ManyTo Many

2017-06-21 Thread 'dtdave' via Django users
I have a model with a manytomany field as follows:
  
  contact = ChainedManyToManyField(
'contacts.Contact',
chained_field="practice",
chained_model_field="practice",
)

Within my admin I have the following for import/export:

contact = fields.Field(column_name='contact name', attribute='contact',
   widget=ManyToManyWidget(Contact, 'contact'))

However, this only returns the contact id.
I am stuck on how I could return the name of the contact instead. Within 
the contact model contact equates to the name of the contact.

Any assistance would be appreciated and apologies in advance if I have 
overlooked the obvious!

-- 
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/344565d3-0144-4069-b1db-6fa4003bd1a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: User Based role in Django

2017-06-21 Thread Jani Tiainen
Hi,

User can't upgrade his group. It is your code that does it. And it is your
code responsibility to track changes etc.

User just may have a button on ui that invokes your code (view) but rest is
really up to you.

21.6.2017 11.24 "Mannu Gupta"  kirjoitti:

> I meant that using your method i.e by making different groups .
> When he upgrade the group .
> How about making another table having user, his subscription level and
> changed_at field(which traces when he /upgrade the group )
>
> Just want to know your suggestion .
>
> Mannu
>
> On Jun 21, 2017 1:48 PM, "Jani Tiainen"  wrote:
>
>> Well its your code, so yes if you write code that does it.
>>
>> It doesn't happen magically for you.
>>
>> 21.6.2017 11.15 "Mannu Gupta"  kirjoitti:
>>
>>> Hi ,
>>> Will I be able to trace if user upgrde the subscription level ?
>>>
>>> Manni
>>>
>>> On Wed, Jun 21, 2017 at 1:41 PM, Jani Tiainen  wrote:
>>>
 Hi,

 We have been using user groups for that. And then we check and filter
 out based on given group(s).

 21.6.2017 10.45 "Mannu Gupta"  kirjoitti:

> I want to make a role based user in Django like the following :-
>
> User with Subscription level 0 will have some feature and some basic
> fields like first name , last name etc.
> User with Subscription level 1 will have some more feature and some
> extra fields  like tax-id , national id , nationality, is_disable etc .
> User with Subscription level 2 will have more features with all the
> fields with the fields with same as fields of Subscription level 1 since 
> he
> has already subscribed only he is upgrading.
> User with Subscription level 3 will have more feature with all the
> fields with the fields same above .
>
> How do i make the user model and related this relate to its role , and
> how do i be able to set permission for different user ?
>
> --
> 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/4bdc5c54-5c90
> -4515-b977-30fcb612b3ff%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
 --
 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/to
 pic/django-users/2JjuGF1-4PU/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/ms
 gid/django-users/CAHn91od9D9aeoigGQ4aN3NKX_woJn%2BENPrePMg%2
 BKEKhZBb-W9Q%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/ms
>>> gid/django-users/CAEDhgmi-cONKSHSBBJOJu6JKPy42-n4zfDY%2BeUmO
>>> QyMXm1bj-A%40mail.gmail.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> 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/to
>> pic/django-users/2JjuGF1-4PU/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.co

Re: Non-primary auto-incrementing field with Postgres

2017-06-21 Thread Melvyn Sopacua
On Monday 19 June 2017 16:29:48 Thomas Hauk wrote:
> I am working on a project that uses Django 1.10.5 with Postgres 9.6
> (and Python 3.6.1).
> 
> I am currently migrating historical data from an old system into the
> new system. This historical data has a table with a (non-primary key)
> "ID" column. I would like to migrate these rows into the new
> database, and have that column be auto-incrementing (starting from,
> say, 10) for new rows inserted.
> 
> I think the way to do this with raw Postgres SQL would be to create a
> serial field, and then run a SQL command like "SELECT
> SETVAL('some_table_field_id_seq', 10)". I think.  :)
> 
> Does Django expose functionality that lets me accomplish this?

First and foremost, verify if ID meets your requirements:
- All values are unique
- They are integers
- Their values are smaller then your new cut-off (10)

Then you can simply transform the field explicitly to primary key and then to 
BigAutoField. 
Setting the next value can be done using RunSQL[1].

-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/1.11/ref/migration-operations/#runsql

-- 
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/2739441.8eksa7p7ra%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: import different entries using filter

2017-06-21 Thread Derek
Your clue is in the word "variable" that you used.  The "variables" for a 
Django model are its fields; so what you are looking for is a value stored 
in your model's field.

e.g. 

service = 
food.objects.get(restaurant-name__icontains='burger-place').values_list('type_of_service',
 
flat=True)

This assumes that your Django "Food" model has a  field called 
'type_of_service'.

Another way to do this would be to first get the restaurant object:

place = food.objects.get(restaurant-name__icontains='burger-place')

Then you can more get to the fields that you need quite easily:

print(place.type_of_service)
print(place.product)

But you may need to think about your database design to ensure the right 
data is being stored in the right models/fields e.g.

https://stackoverflow.com/questions/32366294/database-design-for-food-ordering-system-mysql
http://www.wellho.net/resources/ex.php4?item=s154/sql


On Tuesday, 20 June 2017 06:11:23 UTC+2, jon stan wrote:
>
> hey im trying to import one set of info from a database based on the name 
> of something else if that makes sense.
>
> basically in the database its setup like this:
>
>food-
>   restaurant-name   products type of service
>   
>  (burger-place)(burgers)   (fast food)
>---
>
> im trying to display the products and service type based on the name but i 
> cant figure out how todo that. here's what i have:
>
>  views.py
>   name = 
> food.objects.get(restaurant-name__icontains='burger-place')
>   prod = 
> food.objects.filter(restaurant-name__icontains='burger-place').filter(products__icontains='burgers')
>   service = 
> food.objects.filter(restaurant-name__icontains='burger-place').filter(service__icontains='fast
>  
> food')
>
> but i cant get it to work correctly. i get 'burger-place' for the name, 
> prod, and service variables for some reason. would i have to create 
> completely separate models or is there a way i can get these variables 
> based on the restaurant name?
>

-- 
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/864df46a-1644-4891-a371-926d9fde8a3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Non-primary auto-incrementing field with Postgres

2017-06-21 Thread thauk

On Tuesday, June 20, 2017 at 10:40:05 PM UTC-7, Scot Hacker wrote:
>
> One strategy might be to:
>
> 1) Bring in the data under a different column name ('old_id' ?)
> 2) In a single migration, drop the default ID column,  rename old_id to 
> id, and give it primary_key=True
>

I can't change the primary key for this table, unfortunately.

T
 

-- 
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/f72ddf1d-c7f6-4df3-b2c6-62bba2e4a672%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django_rq or django settings issue ?

2017-06-21 Thread bonet
Hi all,

I'm facing a strange behavior when trying to create Django_rq queues 
configuration dynamically from an environment variable.

my env var is :

CUSTOM_QUEUES=default:q1:q2

into my settings.py I have:

from getenv import env



# Cache
CACHES_DEFAULT = "redis://127.0.0.1:6379/1"
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": env("CACHE_URL", CACHES_DEFAULT),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
'TIMEOUT': 3600
},
}


RQ_QUEUES_REDIS = {'USE_REDIS_CACHE': 'default'}
RQ_QUEUES = {k:RQ_QUEUES_REDIS for k in env('CUSTOM_QUEUES', "default").
split(':')}



I'm expecting the denerated RQ_QUEUES dict to be like this one which is 
working :

RQ_QUEUES = {
'default': {
'USE_REDIS_CACHE': 'default',
},
'q1': {
'USE_REDIS_CACHE': 'default',
},
'q2': {
'USE_REDIS_CACHE': 'default',
},
}


even though the configuration seems to run well and I can see the queues 
from django_rq web page, my workers cannot connect and actually throw this 
error as like there's no queue key in redis


Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File 
"/home/work/virtualenv/runaway_dev/lib/python3.6/site-packages/django/core/management/__init__.py"
, line 350, in execute_from_command_line
utility.execute()
  File 
"/home/work/virtualenv/runaway_dev/lib/python3.6/site-packages/django/core/management/__init__.py"
, line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/home/work/virtualenv/runaway_dev/lib/python3.6/site-packages/django/core/management/base.py"
, line 348, in run_from_argv
self.execute(*args, **cmd_options)
  File 
"/home/work/virtualenv/runaway_dev/lib/python3.6/site-packages/django/core/management/base.py"
, line 399, in execute
output = self.handle(*args, **options)
  File 
"/home/work/virtualenv/runaway_dev/lib/python3.6/site-packages/django_rq/management/commands/rqworker.py"
, line 79, in handle
queues = get_queues(*args)
  File 
"/home/work/virtualenv/runaway_dev/lib/python3.6/site-packages/django_rq/queues.py"
, line 166, in get_queues
queue_params = QUEUES[queue_names[0]]
KeyError: 'default'

By The Way: if I use the Static configuration above it just works well, so 
my suspect is more focused on Django_rq not creating the queues but maybe 
I'm also doing something unproper on the settings of Django. 

Any help would be really appreciated. thanks.

F.

-- 
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/f7e48f76-4120-4bbe-a5b7-d6de7d699eb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Raw SQL - How to approach paging and lazy fetching

2017-06-21 Thread Kevin Yu
Thanks Jani. I was able to solve my original issue using your suggestion.

On Friday, June 16, 2017 at 12:54:26 PM UTC-7, Jani Tiainen wrote:
>
> Yes, even there isn't real foreign keys in  the database you can still 
> join models.
>
> Have been doing that few times with legacy database. When defining fkey 
> you need to point it to corresponding field in fkey attributes in your 
> model if it isnt your target model pk.
>
> And you can join nonmanged models with managed just fine.
>
> 16.6.2017 19.26 "Kevin Yu" > kirjoitti:
>
> Hi Jani,
>
> Thanks for the link. I was aware of this link and actually followed the 
> steps when I started the project. I tried using model but then found out 
> when i need to query a join, it doesn't seem to work unless there's a 
> foreign key between the two models, however, given it's a legacy database, 
> i can't touch the schema at all. Is it possible to query join results with 
> managed=False?
>
> Thanks
>
> On Thursday, June 15, 2017 at 11:31:42 PM UTC-7, Jani Tiainen wrote:
>
>> Hi,
>>
>> Even you do have legacy database, you can use unmanaged models and then 
>> leverage full power of ORM [1].
>>
>> Just create models and in their Meta set managed = False and there you 
>> go. 
>>
>> And what comes to paging - you need to somehow pass offset and limit to 
>> your query.
>>
>> [1] https://docs.djangoproject.com/en/1.11/howto/legacy-databases/
>>
>> On 16.06.2017 02:05, Kevin Yu wrote:
>>
>> Hi All, 
>>
>> I am using raw sql to connect to database. The reason we used raw sql 
>> instead of the Django model is because the database is legacy and is being 
>> shared by multiple applications...
>>
>> I have one use case that I'm struggling right now. Basically I have a 
>> page that fetch more than 1000 results. My query is like this:
>>
>> cursor = connection.cursor()
>> cursor.execute('''
>> SELECT br.id, br.name, br.created_at, br.updated_at,
>> br.branchpoint_str, br.source
>> FROM branches as br
>> LEFT JOIN branches_projects as bp
>> ON br.id = bp.branch_id 
>> WHERE bp.project_id = "%s" AND source != "other"
>> ORDER BY updated_at DESC
>>''', [int(project_id)]
>>)
>>
>> Then in my template, I have this:
>> {% for br in special_branches %}
>>
>>   > link="/files/{{build.image_path}}/build{{build.build_number}}/">
>> {{br.name}}
>> {{br.branchpoint}}
>> {{ br.source|upper }}
>> {{br.updated_at}}
>> {{br.built_at}}
>>   
>> {% endfor %}
>>
>> The current problem is this would create a very long page... I am 
>> wondering how to approach this problem so that I can have different page on 
>> the template, and say 100 result per page, when i click the second page, 
>> then  django will fetch result 100-200.
>>
>> Thanks!
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>>
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/f6a3df97-8218-4fb8-b200-f4535797e135%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> -- 
>> Jani Tiainen
>>
>> -- 
> 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/7e4a44fc-e5ce-4562-8b75-09ba065e34f5%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/461a96ac-60e4-4a0c-aec4-040d3325d2a1%40googlegroups.com.
For more options, v

Need help for defining foreign key based on value from another table

2017-06-21 Thread Kevin Yu
I'm working with a legacy database so I have to set managed=False in the 
model. Here's the 3 related tables:


class Branches(models.Model):
name = models.CharField(max_length=128)
branchpoint_str = models.CharField(max_length=255)
dev_lead_id = models.IntegerField(blank=True, null=True)
source = models.CharField(max_length=255)
state = models.CharField(max_length=255)
kind = models.CharField(max_length=255)
desc = models.TextField(blank=True, null=True)
approved = models.IntegerField()
for_customer = models.IntegerField()
deactivated_at = models.DateTimeField(blank=True, null=True)
created_at = models.DateTimeField(blank=True, null=True)
updated_at = models.DateTimeField(blank=True, null=True)
codb_id = models.IntegerField(blank=True, null=True)
pm_lead_id = models.IntegerField(blank=True, null=True)
version = models.CharField(max_length=20, blank=True, null=True)
path_id = models.IntegerField(blank=True, null=True)
branchpoint_type = models.CharField(max_length=255, blank=True, 
null=True)
branchpoint_id = models.IntegerField(blank=True, null=True)

class Meta:
managed = False
db_table = 'branches'
verbose_name_plural = 'Branches'

class Projects(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=40, primary_key=True)
status = models.CharField(max_length=255)
platform = models.CharField(max_length=255)
enabled = models.IntegerField()
path = models.CharField(max_length=128, blank=True, null=True)
tag_prefix = models.CharField(max_length=64, blank=True, null=True)
created_at = models.DateTimeField(blank=True, null=True)
updated_at = models.DateTimeField(blank=True, null=True)
codb_id = models.IntegerField(blank=True, null=True)
template = models.CharField(max_length=64, blank=True, null=True)
image_path = models.CharField(max_length=128, blank=True, null=True)
repository_id = models.IntegerField(blank=True, null=True)
number_scheme = models.CharField(max_length=32)
special_dir = models.CharField(max_length=32, blank=True, null=True)
project_family_id = models.IntegerField()
class Meta:
managed = False
db_table = 'projects'
verbose_name_plural = 'projects'

class BranchesProjects(models.Model):
# project_id = models.IntegerField()
# branch_id = models.IntegerField()
project = models.ForeignKey(Projects, on_delete=models.CASCADE)
branch = models.ForeignKey(Branches, on_delete=models.CASCADE)

class Meta:
managed = False
db_table = 'branches_projects'

I have been able to do the join using raw(). However, the return object is 
rawqueryset. What I want is queryset so that I can use django-filter to 
process it. My current raw sql is like this:
Branches.objects.raw(
'''SELECT br.id, br.name, br.created_at, br.updated_at,
br.branchpoint_str, br.source
FROM branches as br
LEFT JOIN branches_projects as bp
ON br.id = bp.branch_id 
WHERE bp.project_id = "%s" AND source != "other"
ORDER BY updated_at DES'''

 
My question is, is there a way to achieve the same result using Django's 
queryset? I've also explored  the idea of using the extra() in django extra 

 but 
it doesn't really work for 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/1581448d-bb69-4e85-a35c-62d0bfad88ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need help for defining foreign key based on value from another table

2017-06-21 Thread Kevin Yu
I just found out on Django document, there's an example that's for 
manytomany, using 'through' when defining the foreign key. I think this is 
what i need.

Here's the example:

from django.db import models

class Person(models.Model):
name = models.CharField(max_length=128)

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

class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(Person, through='Membership')

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

class Membership(models.Model):
person = models.ForeignKey(Person, on_delete=models.CASCADE)
group = models.ForeignKey(Group, on_delete=models.CASCADE)
date_joined = models.DateField()
invite_reason = models.CharField(max_length=64)




On Wednesday, June 21, 2017 at 2:49:40 PM UTC-7, Kevin Yu wrote:
>
> I'm working with a legacy database so I have to set managed=False in the 
> model. Here's the 3 related tables:
>
>
> class Branches(models.Model):
> name = models.CharField(max_length=128)
> branchpoint_str = models.CharField(max_length=255)
> dev_lead_id = models.IntegerField(blank=True, null=True)
> source = models.CharField(max_length=255)
> state = models.CharField(max_length=255)
> kind = models.CharField(max_length=255)
> desc = models.TextField(blank=True, null=True)
> approved = models.IntegerField()
> for_customer = models.IntegerField()
> deactivated_at = models.DateTimeField(blank=True, null=True)
> created_at = models.DateTimeField(blank=True, null=True)
> updated_at = models.DateTimeField(blank=True, null=True)
> codb_id = models.IntegerField(blank=True, null=True)
> pm_lead_id = models.IntegerField(blank=True, null=True)
> version = models.CharField(max_length=20, blank=True, null=True)
> path_id = models.IntegerField(blank=True, null=True)
> branchpoint_type = models.CharField(max_length=255, blank=True, 
> null=True)
> branchpoint_id = models.IntegerField(blank=True, null=True)
>
> class Meta:
> managed = False
> db_table = 'branches'
> verbose_name_plural = 'Branches'
>
> class Projects(models.Model):
> id = models.AutoField(primary_key=True)
> name = models.CharField(max_length=40, primary_key=True)
> status = models.CharField(max_length=255)
> platform = models.CharField(max_length=255)
> enabled = models.IntegerField()
> path = models.CharField(max_length=128, blank=True, null=True)
> tag_prefix = models.CharField(max_length=64, blank=True, null=True)
> created_at = models.DateTimeField(blank=True, null=True)
> updated_at = models.DateTimeField(blank=True, null=True)
> codb_id = models.IntegerField(blank=True, null=True)
> template = models.CharField(max_length=64, blank=True, null=True)
> image_path = models.CharField(max_length=128, blank=True, null=True)
> repository_id = models.IntegerField(blank=True, null=True)
> number_scheme = models.CharField(max_length=32)
> special_dir = models.CharField(max_length=32, blank=True, null=True)
> project_family_id = models.IntegerField()
> class Meta:
> managed = False
> db_table = 'projects'
> verbose_name_plural = 'projects'
>
> class BranchesProjects(models.Model):
> # project_id = models.IntegerField()
> # branch_id = models.IntegerField()
> project = models.ForeignKey(Projects, on_delete=models.CASCADE)
> branch = models.ForeignKey(Branches, on_delete=models.CASCADE)
>
> class Meta:
> managed = False
> db_table = 'branches_projects'
>
> I have been able to do the join using raw(). However, the return object is 
> rawqueryset. What I want is queryset so that I can use django-filter to 
> process it. My current raw sql is like this:
> Branches.objects.raw(
> '''SELECT br.id, br.name, br.created_at, br.updated_at,
> br.branchpoint_str, br.source
> FROM branches as br
> LEFT JOIN branches_projects as bp
> ON br.id = bp.branch_id 
> WHERE bp.project_id = "%s" AND source != "other"
> ORDER BY updated_at DES'''
>
>  
> My question is, is there a way to achieve the same result using Django's 
> queryset? I've also explored  the idea of using the extra() in django 
> extra 
> 
>  but 
> it doesn't really work for 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 visi

Re: Abridged summary of django-users@googlegroups.com - 23 updates in 11 topics

2017-06-21 Thread Ranjith Kumar
Hello All,
On Django admin when I tried to update the existing data I’m getting an error,

AttributeError: 'str' object has no attribute '__iter__'


models.py

class SSPDrive(models.Model):

drive_year  = 
models.DateField(verbose_name='Drive year', null=True, blank=True, 
help_text="Enter drive year.")

class Meta:
verbose_name= "SSP Drive"
verbose_name_plural = "SSP Drives"

def __str__(self):
return 
str('SSP'+str(self.drive_year.year)[-2:]+'T'+str(self.drive_year.year+1)[-2:])

class SSPDriveAdmin(admin.ModelAdmin):

save_as = True

class Meta:
model = SSPDrive

admin.site.register(SSPDrive, SSPDriveAdmin)

Can someone help me out, why am I getting this error…

> On 21-Jun-2017, at 6:37 PM, django-users@googlegroups.com wrote:
> 
> django-users@googlegroups.com 
> 
> Google Groups 
> 
>
> 
>
> Today's topic summary  <>
> View all topics 
> 
> import different entries using filter  - 2 Updates
> Non-primary auto-incrementing field with Postgres 
>  - 2 Updates
> User Based role in Django  - 6 Updates
> Django Import/Export ManyTo Many  - 1 Update
> url patterns question  - 3 Updates
> Django phone number validation  - 2 Updates
> If you have multiple custom users - what should you set AUTH_USER_MODEL to? 
>  - 1 Update
> [django] Excluir un ítem de un dropdown en el admin de django 
>  - 1 Update
> Django app to manage PHP-composer repositories  - 
> 2 Updates
> Django website  - 2 Updates
> [django-channels] Issues with model post_save and Group.Send() 
>  - 1 Update
>  <>import different entries using filter  
> 
>   
> Melvyn Sopacua : Jun 20 10:37PM +0200 
> 
> On Monday 19 June 2017 21:11:23 jon stan wrote:
>  
> > service__icontains='fast food')
>  
> > but i cant get it to work correctly. i get 'burger-place' for the
> > name, prod, and service variables for ...more 
> > 
> >  
> Derek : Jun 21 03:12AM -0700 
> 
> Your clue is in the word "variable" that you used. The "variables" for a 
> Django model are its fields; so what you are looking for is a value stored 
> in your model's field.
>  
> e.g. 
>  
> service = ...more 
> 
>  
> Back to top  <>Non-primary auto-incrementing field 
> with Postgres  
> 
>   
> Scot Hacker : Jun 20 10:40PM -0700 
> 
> One strategy might be to:
>  
> 1) Bring in the data under a different column name ('old_id' ?)
> 2) In a single migration, drop the default ID column, rename old_id to id, 
> and give it primary_key=True ...more 
> 
>  
> Melvyn Sopacua : Jun 21 11:43AM +0200 
> 
> On Monday 19 June 2017 16:29:48 Thomas Hauk wrote:
> > serial field, and then run a SQL command like "SELECT
> > SETVAL('some_table_field_id_seq', 10)". I think. :)
>  
> > Does Django expose ...more 
> > 
> >  
> Back to top  <>User Based role in Django  
> 
>   
> Mannu Gupta : Jun 21 12:45AM -0700 
> 
> I want to make a role based user in Django like the following :- 
>  
> User with Subscription level 0 will have some feature and some basic fields 
> like first name , last name etc. 
> ...more 
> 
>  
> Jani Tiainen : Jun 21 11:11AM +0300 
> 
> Hi,
>  
> We have been using user groups for that. And then we check and filter out
> based on given group(s).
>  
> ...more 
> 
>  
> Mannu Gupta : Jun 21 01:44PM +0530 
> 
> Hi ,
> Will I be able to trace if user upgrde the subscription level ?
>  
> Manni
>  
> ...more 
> 
>  
> Jani Tiainen : Jun 21 11:18AM +0300 
> 
> Well its your code, so yes if you write code that does it.
>  
> It doesn't happen magically for you.
>  
> ...more 
> 

Error running ML Code on Django

2017-06-21 Thread A.S. Khangura
I am trying to run a function from views.py which carries some
Machine-Learning code. While I am loading ML model using Joblib from
sklearn It throws error related to tfidf.

Here is traceback: http://dpaste.com/1FPN16G

-- 
Thanks
Arshpreet Singh
Python Developer
Web Development/Data Science/Systems Integration
https://www.linkedin.com/in/arsh840

Life is a journey, not a destination.

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