runserver

2016-12-15 Thread bhupesh kurdia
after running sudo pyhton manage.py runserver it is showing -
Unhandled exception in thread started by 
Traceback (most recent call last):
 pl. 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 visit 
https://groups.google.com/d/msgid/django-users/5cbae84f-6591-4d12-837b-0d8ceffe4870%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: runserver

2016-12-15 Thread GMail
Hi. First off, you don't need sudo to run "runserver" command, unless you're 
using port <1000 (or something), which you also shouldn't, since runserver is 
for development only.

Second, without the actual traceback there's not much one can do to help you.

> On 15 Dec 2016, at 07:31, bhupesh kurdia  wrote:
> 
> after running sudo pyhton manage.py runserver it is showing -
> Unhandled exception in thread started by 
> Traceback (most recent call last):
>  pl. 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 visit 
> https://groups.google.com/d/msgid/django-users/5cbae84f-6591-4d12-837b-0d8ceffe4870%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/5FC29714-034E-4DD5-8956-363C11EC9816%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Strange named parameter passing style

2016-12-15 Thread Alexey Gerasimov


Why "flat" keyword is accepted that way? Why not just as def 
values_list(self, *fields, flat=False)? Because of that I cannot have 
support in my IDE (autocomplete)

def values_list(self, *fields, **kwargs):
flat = kwargs.pop('flat', False)
if kwargs:
raise TypeError('Unexpected keyword arguments to values_list: %s
' % (list(kwargs),))

if flat and len(fields) > 1:
   raise TypeError("'flat' is not valid when values_list is called 
with more than one field.")

_fields = []
expressions = {}

for field in fields:
   if hasattr(field, 'resolve_expression'):
   field_id = str(id(field))
   expressions[field_id] = field
   _fields.append(field_id)
   else:
   _fields.append(field)
   
clone = self._values(*_fields, **expressions)
clone._iterable_class = FlatValuesListIterable if flat else 
ValuesListIterable
return clone


-- 
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/237365e6-2566-4ef3-b86a-005487afb5b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange named parameter passing style

2016-12-15 Thread GMail
Probably for adding other arguments later without braking function signature? 
I'm with you on this one, though. Using kwargs everywhere it's possible really 
helps developing using Django. Maybe this is a subject for 
django-develop...@googlegroups.com. 

> On 15 Dec 2016, at 15:39, Alexey Gerasimov  wrote:
> 
> 
> Why "flat" keyword is accepted that way? Why not just as def 
> values_list(self, *fields, flat=False)? Because of that I cannot have support 
> in my IDE (autocomplete)
> 
> def values_list(self, *fields, **kwargs):
> flat = kwargs.pop('flat', False)
> if kwargs:
> raise TypeError('Unexpected keyword arguments to values_list: %s' 
> % (list(kwargs),))
> 
> if flat and len(fields) > 1:
>raise TypeError("'flat' is not valid when values_list is called 
> with more than one field.")
> 
> _fields = []
> expressions = {}
> 
> for field in fields:
>if hasattr(field, 'resolve_expression'):
>field_id = str(id(field))
>expressions[field_id] = field
>_fields.append(field_id)
>else:
>_fields.append(field)
>
> clone = self._values(*_fields, **expressions)
> clone._iterable_class = FlatValuesListIterable if flat else 
> ValuesListIterable
> return clone
> 
> 
> 
> -- 
> 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/237365e6-2566-4ef3-b86a-005487afb5b4%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/97B8E175-30A8-4DD4-AD85-F0A1A50BC1EA%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Phone number field in form/ model

2016-12-15 Thread Deep Shah
I have not tried this out but you can check this- 

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



On Thursday, December 15, 2016 at 1:07:02 AM UTC+5:30, Lloyd Dube wrote:
>
> Hi,
>
> Has anyone captured phone number information using a Form/ModelForm 
> instance? I have the field as an IntegerField in my model and (for obvious 
> reasons) it truncates the leading '0'. How have you solved this problem, 
> anyone?
>
> -- 
> Regards,
> Sithembewena
>

-- 
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/65418720-d01a-40d1-bed0-387769505982%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Phone number field in form/ model

2016-12-15 Thread John Fabiani
django-phonenumber-field is expecting a charfield and not a int.
Johnf

On Thu, Dec 15, 2016 at 5:12 AM, Deep Shah  wrote:

> I have not tried this out but you can check this-
>
> https://github.com/stefanfoulis/django-phonenumber-field/
>
>
>
> On Thursday, December 15, 2016 at 1:07:02 AM UTC+5:30, Lloyd Dube wrote:
>>
>> Hi,
>>
>> Has anyone captured phone number information using a Form/ModelForm
>> instance? I have the field as an IntegerField in my model and (for obvious
>> reasons) it truncates the leading '0'. How have you solved this problem,
>> anyone?
>>
>> --
>> Regards,
>> Sithembewena
>>
> --
> 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/65418720-d01a-40d1-bed0-387769505982%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/CANDKt80Nx8fR%3Dv_28wCKJZGZLHt%2BKzbZdiiMszDkkpXc%3DcCL-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Opinions on permissions stategy

2016-12-15 Thread Vinicius Assef
On 15 December 2016 at 03:43, Avraham Serour  wrote:
> Hi,
>
> I've given a lot of thought on this, I have also searched for django apps
> that deal with permissions, I didn't find something that implements
> hierarchical object level permissions, I have a feeling that I am
> overcomplicating things if none did this...
>
> Well, first of all I thought of creating a through table for the Object and
> user relation, so permission should have a value (how should I name this?
> level?)

Or "type" (1=read, 2=write, 0=no permission).

It's up to you. ;-)


>
> Actually the module would be the root level, so
> Module->project->project->project->task->task->task
>
> So a user with permissions to a project has also permissions for its
> subprojects and tasks.

This is exactly what I meant by "clear rules". This is one of them. :-)

>
> What do you mean floor?

Using your example above: Module (1st floor)->project (2nd
floor)->project (3rd floor)->project (4th floor)->task (5th
floor)->task (6th floor)->task (7th floor)

"Floor" would be "the level in hierarchy one given object belongs to".

Anyone with write level on the 1st floor, will have the same access on
2nd, 3rd, 4th, 5th, 6th and 7th as well. Otherwise you allow it to be
overriden.

Anyone with write level on the 5th floor, will have the same access on
6th and 7h.

Did you get it?


>
> mptt seems a very nice solution but...
>
> To check an object permission I would need to get the first ascendent with
> permissions registered, with django-mptt I can get all ascendents, this
> could be a problem if the object is too deep.

It'll depend how deep an object can be and the number of children an
object could have.


> I then would need to loop through the ascendents and check if there are
> permissions registered for the current user, this would make yet another
> query, the permissions are on another table

Maybe let the DB solve this through join?

>
> Also, I'm not sure how I would list the objects the user can read for
> example, opening an project page should list only the tasks and subprojects
> the user can read.
> Of course if I ca loop all tasks to get the ones the user can read, but this
> would be prohibitive slow, how can I do this with django mptt in one query?

I don't know django-mptt but maybe you should start reading from your
permissions table and, based on permissions, get which objects the
user could see.

I should know more about your requirements. It's complicated to
explain it here. If you want call me at http://telegram.me/viniciusban

Talking in pt_BR is better in this case for me.

>
> On the other hand the idea of copying the parent permission when an object
> is created have cheap reads, not so expensive writes but I'm afraid would
> make a too big permissions table (number of users X number of lines for most
> tables)

Maybe that's the price to pay for.

But I think it won't be too expensive in terms of performance.

>
> Thanks for the considerations
> Avraham

You're welcome.

--
Vinicius

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


Re: Strange named parameter passing style

2016-12-15 Thread knbk
Python 2 does not support named arguments after *fields, and raises a 
SyntaxError. As long as Django supports Python 2, we're stuck with the 
current approach. I'm sure the new style will be used once Python 2 support 
is dropped.

On Thursday, December 15, 2016 at 1:40:02 PM UTC+1, Alexey Gerasimov wrote:
>
>
> Why "flat" keyword is accepted that way? Why not just as def 
> values_list(self, *fields, flat=False)? Because of that I cannot have 
> support in my IDE (autocomplete)
>
> def values_list(self, *fields, **kwargs):
> flat = kwargs.pop('flat', False)
> if kwargs:
> raise TypeError('Unexpected keyword arguments to values_list: 
> %s' % (list(kwargs),))
>
> if flat and len(fields) > 1:
>raise TypeError("'flat' is not valid when values_list is 
> called with more than one field.")
>
> _fields = []
> expressions = {}
>
> for field in fields:
>if hasattr(field, 'resolve_expression'):
>field_id = str(id(field))
>expressions[field_id] = field
>_fields.append(field_id)
>else:
>_fields.append(field)
>
> clone = self._values(*_fields, **expressions)
> clone._iterable_class = FlatValuesListIterable if flat else 
> ValuesListIterable
> return clone
>
>
>

-- 
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/c35a620c-e864-446c-99fc-93d8af407943%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to customize ASGI ChannelLayer ?

2016-12-15 Thread wang sheng
I an developing a chat app, while some user is offline, I need to persist
 the message from his  online friends .  so , I think it is good choice to
develop a customized ChannelLayer  which will transfer all offline messages
to a consumer worker who save message to cache .  is it right that using
ChannelLayer to do such work ?

   But,  I doesn't find any useful information about How to customize the
ChannelLayer.

-- 
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/CA%2BmnDnr_WapOdOCUJQH%2B-sECPgtGHSCb9cK-ODquq5yEiUjntg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


LoginRequiredMixin and UserPassesTestMixin login_url clash

2016-12-15 Thread Igor Belo
Let me describe my scenario.

I got some views that I want to check two conditions before render:
  1. user is logged in
  2. user fulfilled account details form

If user is not logged in -> redirect to login page.
If user have not fulfilled its account details -> redirect to the form page.

I'm using the *LoginRequiredMixin* to check 1 and the *UserPassesTest* to 
check 2 and the problem is that both mixins use the same login_url 
attribute (or method if I implement get_login_url) and as my views include 
both mixins, it always takes the most-left mixin login_url.

Here's my code:
class LoginRequired(LoginRequiredMixin):
login_url = 'website:join'
redirect_field_name = None

class FulfillAccountRequired(UserPassesTestMixin):
login_url = 'website:account-detail'

def test_func(self):
...

class MyView(FulfillAccountRequired, LoginRequired, ListView):
...

Would be nice if there's a way to set a callable name for login_url (which 
after diving into mixins source I think is not possible).

Is there another clean way to go through?

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/38bf4607-8ca2-4ee4-9065-9dfa353e5fcf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error 500 'NoneType' object

2016-12-15 Thread Zachary Sohovich
Yea, thats correct. I have no idea why I did that thank you for pointing 
that out. It looks like that's what was causing my internal server error 
too. Thank you!

On Thursday, December 15, 2016 at 6:55:02 AM UTC-8, Vinicius Assef wrote:
>
> AFAIK you should use:
>
> messages.error(request, 'There was an error submitting your email. Try 
> again.')
>
> instead of
>
> messages.error = messages.error(request, 'There was an error submitting 
> your email. Try again.')
>
> The messages.error() method doesn't return anything.
>
> See here: 
> https://docs.djangoproject.com/en/1.10/_modules/django/contrib/messages/api/#get_messages
>
>
> --
> Vinicius
>
>
>
> On 15 December 2016 at 03:48, Avraham Serour  > wrote:
>
>> it seems you have a bug on your error handling, it seems messages.error 
>> is None
>>
>> Can you reproduce this locally? your tests should also cover the error 
>> handling
>>
>> On Thu, Dec 15, 2016 at 1:45 AM, Zachary Sohovich > > wrote:
>>
>>> I created a simple contact form with Django for a client. I am using the 
>>> Messages framework to display an error or success message on form 
>>> submission. If the form encounters any errors once or twice, we're good. It 
>>> displays the error message. But, after the third of fourth time there's an 
>>> error, I eventually start getting an Internal Server Error (500). 
>>>
>>> Here's my *forms.py*
>>>
>>> from django import forms
>>> from captcha.fields import ReCaptchaField
>>> class EmailForm(forms.Form):
>>> captcha = ReCaptchaField()
>>> contact_name = forms.CharField(label='Name',max_length=100,required=
>>> True,widget=forms.TextInput(attrs={'required':'true'}))
>>> contact_email = forms.EmailField(required=True,max_length=100,label=
>>> 'Email',widget=forms.EmailInput(attrs={'required':'true'}))
>>> content = forms.CharField(required=True,widget=forms.Textarea(attrs
>>> ={'required':'true'}))
>>>
>>>
>>> Here's my *views.py*
>>>
>>> from django.shortcuts import render, redirect
>>> from django.contrib import messages
>>> from .models import Employee
>>> from .forms import EmailForm
>>> from django.core.mail import send_mail
>>> from django.template import Context
>>> from django.template.loader import get_template
>>>
>>>
>>> # Create your views here.
>>>
>>>
>>> def home(request):
>>> return render(request, 'index.html')
>>>
>>>
>>> def team(request):
>>> members = Employee.objects.all()
>>> return render(request, 'team.html', {'members':members})
>>>
>>>
>>> def contact(request):
>>> form_class = EmailForm
>>> if request.method == 'POST':
>>> form = EmailForm(request.POST)
>>> if form.is_valid():
>>> contact_name = request.POST.get('contact_name', '')
>>> contact_email = request.POST.get('contact_email', '')
>>> form_content = request.POST.get('content', '')
>>> template = get_template('contact_template.txt')
>>> context = Context({'contact_name':contact_name,
>>> 'contact_email':contact_email,'form_content':form_content,})
>>> content = template.render(context)
>>> send_mail('Website Email from ' + contact_name,content,
>>> contact_email, ['crowdc...@sneakycr0w.com '], fail_silently
>>> =False)
>>> messages.success(request,'Email was successful!')
>>> else: 
>>> try:
>>> messages.error = messages.error(request, 'There was an 
>>> error submitting your email. Try again.')
>>> except TypeError:
>>> messages.error = messages.error(request, 'There was an 
>>> error submitting your email. Try again.')
>>> return render(request, 'contact.html', {'form': form_class, })
>>>
>>>
>>> And then here's the* trace*:
>>>
>>>
>>>
>>> Internal Server Error: /contact/
>>>
>>> TypeError at /contact/ ‘NoneType’ object is not callable
>>>
>>> Request Method: POST Request URL: https:
>>> //www.crowdcontrolstudios.com/contact/ 
>>> 
>>>  
>>> Django Version: 1.10.4 Python Executable: 
>>> /home/django/django/crowdcontrol_env/bin/python3 Python Version: 3.5.2 
>>> Python Path: ['/home/django/django', 
>>> ‘/home/django/django/crowdcontrol_env/bin’, 
>>> ‘/home/django/django/crowdcontrol_env/lib/python35.zip’, 
>>> ‘/home/django/django/crowdcontrol_env/lib/python3.5’, 
>>> ‘/home/django/django/crowdcontrol_env/lib/python3.5/plat-x86_64-linux-gnu’, 
>>> ‘/home/django/django/crowdcontrol_env/lib/python3.5/lib-dynload’, 
>>> ‘/usr/lib/python3.5’, ‘/usr/lib/python3.5/plat-x86_64-linux-gnu’, 
>>> ‘/home/django/django/crowdcontrol_env/lib/python3.5/site-packages’] Server 
>>> time: Wed, 14 Dec 20

M2M Question

2016-12-15 Thread Matthew Pava
I have a Document model that has an M2M-symmetrical field on itself.  The idea 
is that we can "link" documents to other documents.  It's very simple to find 
the linked documents of a particular document, but is there an easy way to get 
all the linked documents of the linked documents of the document in question?  
I will probably have to write my own QuerySet or ModelManager function, but I 
was just curious if Django had something built in.

For example:
A is linked to J, C, K.

è J is linked to A

è C is linked to A

è K is linked to A
B is linked to J, M, P.

è J is linked to B

è M is linked to B

è P is linked to B
C is linked to O.

è O is linked to C
D is linked to O, P, R.

è O is linked to D

è P is linked to D

è R is linked to D

So when I get the entire "chain" of documents linked to A, I would get 
something like this:
J, C, K, B, O, D, P, R, M

Since J is linked to A and B, K is linked to A, and C is linked to A and O and 
O is linked to D, and D is linked to O and P, R is linked to D and P is linked 
to B which is linked to M (and J).
Hmmm...my contrived example exploded on me more than I intended...

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


Re: LoginRequiredMixin and UserPassesTestMixin login_url clash

2016-12-15 Thread Igor Belo
I came up with a solution by overriding the *handle_no_permission* method 
from the *UserPassesTestMixin*:

class FulfillAccountRequired(UserPassesTestMixin):
def test_func(self):
return self.request.user.account_completed

def handle_no_permission(self):
return redirect('website:account-detail')

Not an elegant solution at all but solved my problem. Wondering if it 
worths to open a pull request.
Well, hope it helps someone in the future.

On Thursday, December 15, 2016 at 3:53:38 PM UTC-2, Igor Belo wrote:
>
> Let me describe my scenario.
>
> I got some views that I want to check two conditions before render:
>   1. user is logged in
>   2. user fulfilled account details form
>
> If user is not logged in -> redirect to login page.
> If user have not fulfilled its account details -> redirect to the form 
> page.
>
> I'm using the *LoginRequiredMixin* to check 1 and the *UserPassesTest* to 
> check 2 and the problem is that both mixins use the same login_url 
> attribute (or method if I implement get_login_url) and as my views include 
> both mixins, it always takes the most-left mixin login_url.
>
> Here's my code:
> class LoginRequired(LoginRequiredMixin):
> login_url = 'website:join'
> redirect_field_name = None
>
> class FulfillAccountRequired(UserPassesTestMixin):
> login_url = 'website:account-detail'
> 
> def test_func(self):
> ...
>
> class MyView(FulfillAccountRequired, LoginRequired, ListView):
> ...
>
> Would be nice if there's a way to set a callable name for login_url (which 
> after diving into mixins source I think is not possible).
>
> Is there another clean way to go through?
>
> 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/1a77c004-dab2-4c30-89e3-5bb753177cfd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: M2M Question

2016-12-15 Thread Mike Dewhirst

On 16/12/2016 8:52 AM, Matthew Pava wrote:


I have a Document model that has an M2M-symmetrical field on itself.  
The idea is that we can “link” documents to other documents.  It’s 
very simple to find the linked documents of a particular document, but 
is there an easy way to get all the linked documents of the linked 
documents of the document in question?  I will probably have to write 
my own QuerySet or ModelManager function, but I was just curious if 
Django had something built in.


For example:

A is linked to J, C, K.

èJ is linked to A

èC is linked to A

èK is linked to A

B is linked to J, M, P.

èJ is linked to B

èM is linked to B

èP is linked to B

C is linked to O.

èO is linked to C

D is linked to O, P, R.

èO is linked to D

èP is linked to D

èR is linked to D

So when I get the entire “chain” of documents linked to A, I would get 
something like this:


J, C, K, B, O, D, P, R, M



I would put a method on the document model to  return a queryset with 
respect to itself. To do this I would nominate the "through" table and  
have a model class which maps to it. That model will have two PKs to the 
document model. The document model method(s) which return querysets 
query the "through" table.


Also have a look at select_related

https://docs.djangoproject.com/en/1.10/ref/models/querysets/#select-related

Since J is linked to A and B, K is linked to A, and C is linked to A 
and O and O is linked to D, and D is linked to O and P, R is linked to 
D and P is linked to B which is linked to M (and J).


Hmmm…my contrived example exploded on me more than I intended…

--
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/7a3247baf2234f8ab3a7a4db40bcf8c5%40ISS1.ISS.LOCAL 
.

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/42fa7086-0cc7-db66-afc2-01ce8089f3a1%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: how to customize ASGI ChannelLayer ?

2016-12-15 Thread Andrew Godwin
No, that's not what a channel layer is meant to do - it's for short term
buffering (messages expire after a minute by default).

I suggest you use a database.

Andrew

On 15 Dec 2016 17:53, "wang sheng"  wrote:

> I an developing a chat app, while some user is offline, I need to persist
>  the message from his  online friends .  so , I think it is good choice to
> develop a customized ChannelLayer  which will transfer all offline messages
> to a consumer worker who save message to cache .  is it right that using
> ChannelLayer to do such work ?
>
>But,  I doesn't find any useful information about How to customize the
> ChannelLayer.
>
> --
> 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/CA%2BmnDnr_WapOdOCUJQH%2B-sECPgtGHSCb9cK-
> ODquq5yEiUjntg%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/CAFwN1upps%3DJd1LyW8X01wjWOSRmTvS9nYsz4qoQpd98P_tXjNA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.