Re: Window expression inside Subquery

2018-02-28 Thread Tomáš Ehrlich
It seems to be a bug in Django. Here's the ticket 
(https://code.djangoproject.com/ticket/29172) with
patch and tests if anyone is interested in this topic.

Cheers,
   Tom


Dne čtvrtek 1. března 2018 7:38:13 UTC+1 Tomáš Ehrlich napsal(a):
>
> Hey folks,
> I’m getting an AttributeError: 'NoneType' object has no attribute 
> ‘relabeled_clone'
> when using Window expression inside Subquery:
>
> Message.objects
> .filter(pk__in=Subquery(
> Message.objects
> .annotate(latest_pk=Window(
> expression=FirstValue('pk'),
> partition_by=[F('conversation_id')],
> order_by=F('date').desc(),
> ))
> .values('latest_pk')
> ))
>
> I would like to translate this SQL statement to Django ORM:
>
> SELECT
>   "conversations_message"."id",
>   "conversations_message"."conversation_id",
>   "conversations_message"."author_id",
>   "conversations_message"."content",
>   "conversations_message"."date"
> FROM "conversations_message"
> WHERE "conversations_message"."id" IN (
>   SELECT first_value("id") OVER (PARTITION BY "conversation_id" ORDER BY 
> "date" DESC)
>   FROM conversations_message
> )
>
> I tested SQL statement and it works. I’m trying to select all 
> conversations in DB
> and prefetch latest message in each conversation.
>
>
> I’ve found this note about using aggregates in Subqueries:
>
> https://docs.djangoproject.com/en/2.0/ref/models/expressions/#using-aggregates-within-a-subquery-expression
> but it doesn’t seem to be related to my case.
>
> I could however replace Window function with Max aggregate:
>
> Message.objects.filter(pk__in=Subquery(
> Message.objects
> .order_by()
> .values('conversation')
> .annotate(latest=Max('id'))
> .values('latest')
> )
> )
>
> This works too, but I don’t feel very comfortable using Max on `id`.
>
>
> Related question: Is there a better way to prefetch latest related items? 
> Both in Django and raw SQL.
>
> Thanks in advance!
>
>
> Cheers,
>Tom
>
>

-- 
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/9558fa54-089d-4dd3-8e60-09fdf63712ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Fetching next and/or prior objects given an arbitrary ordering

2018-02-28 Thread Bernd Wechner

Mike,

Yep, adding pk as a final tie breaker is trivial, but not the issue ;-). 
Alas adding a sequencing field is not an option because I am looking for 
a generic solution, akin to what the admin site on Django offers, I have 
a model browser that I want to browse any of my models with.  And I was 
in fact using a date_time sequencer, only found that it broke in the 
generic sense for any ordering and with ties.


Moreover, without understanding the full context in your example you 
seem be fetching a pile of questions and then walking them to find the 
prior (I prefer the term "prior" as "last" has unfortunate ambiguity) 
and next questions, your set defined by 
"instruction_id=question.instruction.pk". My guess is that in your 
scenario that list is likely to be small (<1000 objects ;-) and this 
strategy becomes unappealing again if that list could be arbitrarily 
large (millions, or more) which is true for a generic scenario which 
makes no assumptions about the model other than what is provided by its 
ordering and known about the current object.


Regards,

Bernd.

Mike Dewhirst wrote:

On 1/03/2018 10:50 AM, Bernd Wechner wrote:
> Julio,
>
> Thanks for giving it some though. But I think you misread me a little. 
> I am using the get() only to illustrate that the precondition is, I 
> have a single object. The goal then is find a neighboring object (as 
> defined by the ordering in the model).

>
> Yes indeed, a filter is the first and primary candidate for achieving 
> that, but can you write one that respects an abritrary ordering 
> involving multiple fields, as I exemplified with:

>
> |
> classThing(models.Model):
>      field1 =...
>      field2 =...
>      field2 =...
> classMeta:
>          ordering =['field1','-field2','field3']
> |
>
> Also consider that the ordering thus specified does not stipulate 
> uniqueness in any way, that is many neighboring things in an ordered 
> list may have identical values of field1, field2 and field3.


Nothing to stop you adding 'pk' or '-pk' to the ordering list.

I have done something similar recently where an online training course
leads the user with next and previous links to the next or previous
questions. At the first and last question for each set of instruction,
the links morph into previous and next instruction.

My approach relies on there being only a few questions per instruction.
It isn't very elegant because it tramples over the 'last' values until
the last man standing is correct and it bails out as soon as it finds a
greater 'next' value.

I did need/want a separate numeric ordering field because a trainer
writing up a course needs a sequence to force instruction items and
questions into adjustable arbitrary orders. Hence, the model save()
method updates a num_sequence float field from the user entered sequence
char field.

I haven't thought about < or > in the context of your ['field1',
'-field2', 'field3'] ordering but I went for a num_sequence float field
because '11' < '2' but 2.0 < 11.0 and so on.

The view code goes like this ...

def get_last_next_question_links(question, instruction, course, user):
  lastlink = 'No previous question'
  nextlink = 'No more questions'
  questions = 
Question.objects.filter(instruction_id=question.instruction.pk)
  for obj in questions:
  if obj.num_sequence < question.num_sequence:
  lasturl = '/question/%s/' % obj.pk
  lastname = 'Previous Question %s' % obj.sequence
  lastlink = '%s' % (lasturl, lastname)
  elif obj.num_sequence > question.num_sequence:
  nexturl = '/question/%s/' % obj.pk
  nextname = 'Next Question %s' % obj.sequence
  nextlink = '%s' % (nexturl, nextname)
  break
  if lastlink.startswith('No'):
  lastlink = get_instruction_link(
  course, instruction, user, next=False
  )
  if nextlink.startswith('No'):
  nextlink = get_instruction_link(
  course, instruction, user, next=True
  )
  return lastlink, nextlink


hth

>
> I'm not sure how Django sorts those ties, but imagine it either defers 
> to the underlying database engine (i.e. uses the sort simply to 
> generate an ORDER BY clause in the SQL for example in the above case:

>
> |
> ORDER BY field1 ASC,field2 DESC,field3 ASC
> |
>
> and lets the underlying database engine define how ties are ordered. 
> Or it could add a pk tie breaker to the end. Matters little, the 
> problem remains: how to find neighbors given an arbitrary ordering and 
> ties.

>
> Can you write a filter clause to do that? I'm curious on that front.
>
> It's easy of course with one sort field with unique values collapsing 
> to an __gt or __lt filter folllowed by first() or last() respectively 
> (not sure that injects a LIMIT clause into the SQL or collects a list 
> and then creams one element from it - I'll test a little I think).

>
> In the mean time, I still feel 

Window expression inside Subquery

2018-02-28 Thread Tomáš Ehrlich
Hey folks,
I’m getting an AttributeError: 'NoneType' object has no attribute 
‘relabeled_clone'
when using Window expression inside Subquery:

Message.objects
.filter(pk__in=Subquery(
Message.objects
.annotate(latest_pk=Window(
expression=FirstValue('pk'),
partition_by=[F('conversation_id')],
order_by=F('date').desc(),
))
.values('latest_pk')
))

I would like to translate this SQL statement to Django ORM:

SELECT
  "conversations_message"."id",
  "conversations_message"."conversation_id",
  "conversations_message"."author_id",
  "conversations_message"."content",
  "conversations_message"."date"
FROM "conversations_message"
WHERE "conversations_message"."id" IN (
  SELECT first_value("id") OVER (PARTITION BY "conversation_id" ORDER BY "date" 
DESC)
  FROM conversations_message
)

I tested SQL statement and it works. I’m trying to select all conversations in 
DB
and prefetch latest message in each conversation.


I’ve found this note about using aggregates in Subqueries:
https://docs.djangoproject.com/en/2.0/ref/models/expressions/#using-aggregates-within-a-subquery-expression
 

but it doesn’t seem to be related to my case.

I could however replace Window function with Max aggregate:

Message.objects.filter(pk__in=Subquery(
Message.objects
.order_by()
.values('conversation')
.annotate(latest=Max('id'))
.values('latest')
)
)

This works too, but I don’t feel very comfortable using Max on `id`.


Related question: Is there a better way to prefetch latest related items? Both 
in Django and raw SQL.

Thanks in advance!


Cheers,
   Tom

-- 
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/DD9FBE1F-E4FB-483E-B85B-BBC2BC36F6BB%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP


Re: Fetching next and/or prior objects given an arbitrary ordering

2018-02-28 Thread Mike Dewhirst

On 1/03/2018 10:50 AM, Bernd Wechner wrote:

Julio,

Thanks for giving it some though. But I think you misread me a little. 
I am using the get() only to illustrate that the precondition is, I 
have a single object. The goal then is find a neighboring object (as 
defined by the ordering in the model).


Yes indeed, a filter is the first and primary candidate for achieving 
that, but can you write one that respects an abritrary ordering 
involving multiple fields, as I exemplified with:


|
classThing(models.Model):
     field1 =...
     field2 =...
     field2 =...
classMeta:
         ordering =['field1','-field2','field3']
|

Also consider that the ordering thus specified does not stipulate 
uniqueness in any way, that is many neighboring things in an ordered 
list may have identical values of field1, field2 and field3.


Nothing to stop you adding 'pk' or '-pk' to the ordering list.

I have done something similar recently where an online training course 
leads the user with next and previous links to the next or previous 
questions. At the first and last question for each set of instruction, 
the links morph into previous and next instruction.


My approach relies on there being only a few questions per instruction. 
It isn't very elegant because it tramples over the 'last' values until 
the last man standing is correct and it bails out as soon as it finds a 
greater 'next' value.


I did need/want a separate numeric ordering field because a trainer 
writing up a course needs a sequence to force instruction items and 
questions into adjustable arbitrary orders. Hence, the model save() 
method updates a num_sequence float field from the user entered sequence 
char field.


I haven't thought about < or > in the context of your ['field1', 
'-field2', 'field3'] ordering but I went for a num_sequence float field 
because '11' < '2' but 2.0 < 11.0 and so on.


The view code goes like this ...

def get_last_next_question_links(question, instruction, course, user):
lastlink = 'No previous question'
nextlink = 'No more questions'
questions = Question.objects.filter(instruction_id=question.instruction.pk)
for obj in questions:
if obj.num_sequence < question.num_sequence:
lasturl = '/question/%s/' % obj.pk
lastname = 'Previous Question %s' % obj.sequence
lastlink = '%s' % (lasturl, lastname)
elif obj.num_sequence > question.num_sequence:
nexturl = '/question/%s/' % obj.pk
nextname = 'Next Question %s' % obj.sequence
nextlink = '%s' % (nexturl, nextname)
break
if lastlink.startswith('No'):
lastlink = get_instruction_link(
course, instruction, user, next=False
)
if nextlink.startswith('No'):
nextlink = get_instruction_link(
course, instruction, user, next=True
)
return lastlink, nextlink


hth



I'm not sure how Django sorts those ties, but imagine it either defers 
to the underlying database engine (i.e. uses the sort simply to 
generate an ORDER BY clause in the SQL for example in the above case:


|
ORDER BY field1 ASC,field2 DESC,field3 ASC
|

and lets the underlying database engine define how ties are ordered. 
Or it could add a pk tie breaker to the end. Matters little, the 
problem remains: how to find neighbors given an arbitrary ordering and 
ties.


Can you write a filter clause to do that? I'm curious on that front.

It's easy of course with one sort field with unique values collapsing 
to an __gt or __lt filter folllowed by first() or last() respectively 
(not sure that injects a LIMIT clause into the SQL or collects a list 
and then creams one element from it - I'll test a little I think).


In the mean time, I still feel this has to be a fairly standard use 
case. It's about browsing objects in a table one by one, with a next 
and previous button given an ordering specified in the model and no 
guarantee of uniqueness on the (sort keys).


Regards,

Bernd.

On Thursday, 1 March 2018 00:58:58 UTC+11, Julio Biason wrote:

Hi Bernd,

Well, the thing with `get()` is that it will return only one
object. What you're looking for is `filter()`.

Say, you want all the things that have an ID after a certain
value. So you get `list_of_things =
Things.objects.filter(pk__gte=...)`. Now it'll return the list,
with all elements after the one you asked.

If you want the previous and next, you can do `list_of_previous =
Things.objects.filter(pk__lt=...).limit(1)` and `list_of_next =
Things.objects.filter(pk__gt).limit(1)`.

Or something like that ;P

On Wed, Feb 28, 2018 at 8:56 AM, Bernd Wechner
 wrote:

I'm a bit stumped on this. Given an arbitrary ordering as
specified by the ordering meta option:

https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering

Re: Is there a way to make a field both foreignKey or allow user to fill it in themself?

2018-02-28 Thread Mike Dewhirst

On 1/03/2018 3:20 PM, Matemática A3K wrote:



On Wed, Feb 28, 2018 at 12:46 AM, Mike Dewhirst > wrote:


On 28/02/2018 1:58 PM, Alexander Joseph wrote:

Sorry, I think my question was confusing. What I want to do is
allow the user to either select a user from a drop down list
of users from the ForeignKey in the Users model, or if there
is not a user suitable to select in the drop down, they can
manually type in a name themselves.


In the same field that would require a hack of the first water. 
Way above my pay grade. For me, anything which equates an existing
user object with a string typed in is likely to end in misery.

Otherwise a separate CharField for the typed in name and null=True
and blank=True in the ForeignKey ought to work.

Mike


Indeed, what you can also do - besides the nullable FK, is process 
that in the Form where if the FK is null and the the charfield is not 
None, then create a User (maybe non active) with that name and assign 
it to the FK.


It will depend on the use-case requirements but I think that could get 
slightly messy. You need to ensure you are not creating duplicate 
people. For example you would likely need case-insensitive names.







Thanks for your reply



On Tuesday, February 27, 2018 at 7:45:51 PM UTC-7, Mike
Dewhirst wrote:

    On 28/02/2018 1:26 AM, Alexander Joseph wrote:
    > Is there a way to make a form field or model field
either a foreign
    > key reference or allow the user to fill in something
themselves?
    I'm
    > making a fixed assets app and each fixed asset has an
owner field,
    > which I would like to assign to an app user if possible,
and if not
    > possible be able to fill in a name myself.

    Yes. Make the ForeignKey in the model null=True and
blank=True so
    it can
    exist all alone. Then you can limit_choices_to whatever
whatever
    suits
    your requirements ...


https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to


   

>


    hth
    Mike


    >
    > 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/98c44317-0993-4d41-9d25-33f8a9821dce%40googlegroups.com


   

>

    >
   


   

>>.

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

    

Re: What happened to CollapsedFieldsets.js?

2018-02-28 Thread Matemática A3K
On Tue, Feb 27, 2018 at 1:28 PM, Alan  wrote:

> Hi there,
>
> Well, I used that like 8 years ago. Just wondering what's the current
> solution for Django 2.0 if one want to collapse fields in forms.
>
>
AFAIK is to write your own javascript (or use a third-party library /
"toolkit") for doing that. You can see the implementation in the admin as a
reference:
https://github.com/django/django/blob/master/django/contrib/admin/static/admin/js/collapse.js


> Thanks in advance,
>
> Alan
>
> --
> I'll cycle across Britain in 2018 for a charity, would you consider
> supporting my cause? http://uk.virginmoneygiving.com/AlanSilva
> Many thanks!
> --
> Alan Wilter SOUSA da SILVA, DSc
> Senior Bioinformatician, UniProt
> European Bioinformatics Institute (EMBL-EBI)
> European Molecular Biology Laboratory
> Wellcome Trust Genome Campus
> Hinxton
> Cambridge CB10 1SD
> United Kingdom
> Tel: +44 (0)1223 494588
>
> --
> 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/CAEznbznf1TyN-LSr5apdf7LGZJDR9Lco96GcJqMS%
> 3DF4vK7jRQA%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/CA%2BFDnhKz%3Dh2A1i_%2BVn0_pZyvWx6kjEKT9%3DjXKn2jBoDFZuYmmw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Static/constant dictionary for get_initial or get_form_kwargs

2018-02-28 Thread Matemática A3K
On Tue, Feb 27, 2018 at 9:10 PM, Bob Glassett 
wrote:

> Hello,
>
> Trying to bring a django app into production, and I ran into a real
> headscratcher.
>
> I have a Class based view inherited from create.  When the page reloads,
> after validation, I check the initial dictionary for a field's value to
> fill in the queryset for a different field.
>
> I'm getting sporadic errors about one of the fields not found in the
> initial object.  When I looked closer into the problem, the initial
> dicitonary matched a form for a totally different model.
>
> If I need to pre-populate the initial dictionary, I override the
> get_initial and return the dictionary that I want.  I am not setting
> initial= in the class definition.  Is this the right way to do this task?
>
> I am concerned about a static initial dictionary sticking around.  The
> base edit class returns a copy of the initial dictionary, but if the
> initial dicitonary somehow has invalid values in it, I could be seeing this
> for all my forms.
>
> This is what I did for the initial dictionary:
>
> class UserCreateView(AdminCreateView):
>
> model=User
>
> success_url='/portal/accounts/list'
>
> form_class=PortalUserForm
>
>
>
> def get_form_kwargs(self):
>
> kwargs = super(UserCreateView, self).get_form_kwargs()
>
> kwargs.update({'request' : self.request})
>
> return kwargs
>
>
>
> def get_initial(self):
>
> return {}
>
>
> On a ModelForm (unrelated to the form/model above) I was trying to access
> the self.initial for a particular field, which threw a Key exception.  The
> initial dictionary passed down on the yellow screen did not match the form
> or data for the view at all.
>
>
> kwargs:
>
>
>
> {'initial': {'agency': ,
>  'canEnterMealCounts': False,
>  'canManageCalendar': True,
>  'canManageCustomerAllergies': True,
>  'canManageFieldTrips': True,
>  'canManageSocializations': True,
>  'canManageSpecialOrders': True,
>  'canManageSupplies': False,
>  'canPrintMenus': True,
>  'chefablesUser': False,
>  'location': ,
>  'phone': PhoneNumber(country_code=1, national_number=2018158136, 
> extension=None, italian_leading_zero=None, number_of_leading_zeros=None, 
> country_code_source=1, preferred_domestic_carrier_code=None)},
>  'instance': None,
>  'prefix': None}
>
>
> I have no idea where that initial dictionary came from.  My
> get_form_kwargs looks like this:
>
>
> def get_form_kwargs(self):
>
> kwargs = super(PendingLabelsCreateView, self).get_form_kwargs()
>
> kwargs.update({'user': self.request.user})
>
> return kwargs
>
>
> The direct ancestor doesn;'t have get_form_kwargs defined, and that is
> defined as such:
>
>
> class AdminCreateView(LoginRequiredMixin, UserPassesTestMixin,
> CreateView):
>
>
> I need to understand where that initial value came from and determine if I
> have static values where I don't want them.
>
>
> Maybe they are set in the Form?


> 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/db24def3-f8cc-4954-bbd3-72b6ed3fa0d6%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/CA%2BFDnh%2BCu3FKXLn_-T7FT34c7bvmsSM6GMxgoM3eN37PuTF1Cg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to make a field both foreignKey or allow user to fill it in themself?

2018-02-28 Thread Matemática A3K
On Wed, Feb 28, 2018 at 12:46 AM, Mike Dewhirst 
wrote:

> On 28/02/2018 1:58 PM, Alexander Joseph wrote:
>
>> Sorry, I think my question was confusing. What I want to do is allow the
>> user to either select a user from a drop down list of users from the
>> ForeignKey in the Users model, or if there is not a user suitable to select
>> in the drop down, they can manually type in a name themselves.
>>
>
> In the same field that would require a hack of the first water.  Way above
> my pay grade. For me, anything which equates an existing user object with a
> string typed in is likely to end in misery.
>
> Otherwise a separate CharField for the typed in name and null=True and
> blank=True in the ForeignKey ought to work.
>
> Mike
>

Indeed, what you can also do - besides the nullable FK, is process that in
the Form where if the FK is null and the the charfield is not None, then
create a User (maybe non active) with that name and assign it to the FK.


>
>
>> Thanks for your reply
>>
>>
>>
>> On Tuesday, February 27, 2018 at 7:45:51 PM UTC-7, Mike Dewhirst wrote:
>>
>> On 28/02/2018 1:26 AM, Alexander Joseph wrote:
>> > Is there a way to make a form field or model field either a foreign
>> > key reference or allow the user to fill in something themselves?
>> I'm
>> > making a fixed assets app and each fixed asset has an owner field,
>> > which I would like to assign to an app user if possible, and if not
>> > possible be able to fill in a name myself.
>>
>> Yes. Make the ForeignKey in the model null=True and blank=True so
>> it can
>> exist all alone. Then you can limit_choices_to whatever whatever
>> suits
>> your requirements ...
>>
>> https://docs.djangoproject.com/en/1.11/ref/models/fields/#
>> django.db.models.ForeignKey.limit_choices_to
>> > django.db.models.ForeignKey.limit_choices_to>
>>
>>
>> hth
>> Mike
>>
>>
>> >
>> > 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/98c44317-0993
>> -4d41-9d25-33f8a9821dce%40googlegroups.com
>> > 3-4d41-9d25-33f8a9821dce%40googlegroups.com>
>>
>> >
>> > 3-4d41-9d25-33f8a9821dce%40googlegroups.com?utm_medium=email
>> _source=footer
>> > 3-4d41-9d25-33f8a9821dce%40googlegroups.com?utm_medium=email
>> _source=footer>>.
>>
>> > 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 > 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/dd78c8cf-1892-4740-b3cb-1e384b9bd788%40googlegroups.com
>> > 2-4740-b3cb-1e384b9bd788%40googlegroups.com?utm_medium=email
>> _source=footer>.
>> 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/4facfe44-e50e-e7d4-e41a-1c82775a8f7f%40dewhirst.com.au.
>
> 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 

Re: Fetching next and/or prior objects given an arbitrary ordering

2018-02-28 Thread Bernd Wechner
I should add that one solution which I find functional but unattractive is 
to build a and ordered list of PKs:

things = list(Thing.objects.all().values_list('pk', flat=True))

then find the PK of the current object in that list and look one ahead or 
behind to get the PK of the neighbor and then fetch it with get(). The 
problem with this is that it loads an arbitrarily large list of PKs into 
memory for a job that should have a solution in the form of a database 
query that the ORM can execute lazily and receiving just one object.

Note that the list of Things above is ordered by Django in respect of the 
ordering defined in the model meta class, that is, this is an ordered list.

Regards,

Bernd.

On Thursday, 1 March 2018 00:58:58 UTC+11, Julio Biason wrote:
>
> Hi Bernd,
>
> Well, the thing with `get()` is that it will return only one object. What 
> you're looking for is `filter()`.
>
> Say, you want all the things that have an ID after a certain value. So you 
> get `list_of_things = Things.objects.filter(pk__gte=...)`. Now it'll return 
> the list, with all elements after the one you asked.
>
> If you want the previous and next, you can do `list_of_previous = 
> Things.objects.filter(pk__lt=...).limit(1)` and `list_of_next = 
> Things.objects.filter(pk__gt).limit(1)`.
>
> Or something like that ;P
>
> On Wed, Feb 28, 2018 at 8:56 AM, Bernd Wechner  > wrote:
>
>> I'm a bit stumped on this. Given an arbitrary ordering as specified by 
>> the ordering meta option:
>>
>> https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering
>>
>> for example:
>>
>> class Thing(models.Model):
>> field1 = ...
>> field2 = ...
>> field2 = ...
>> class Meta:
>> ordering = ['field1', '-field2', 'field3']
>>
>> given an instant of Thing:
>>
>> thing = Thing.objects.get(pk=...)
>>
>> how can I get the next Thing after that one, and/or the prior Thing 
>> before that one as they appear on the sorted list of Things.
>>
>> It's got me stumped as I can't think of an easy way to build a filter 
>> even with Q object for an arbitrary ordering given there can be multiple 
>> fields in ordering and multiple Things can have the same ordering list 
>> (i.e. there can be ties - that Django must resolve either arbitrarily or 
>> with an implicit pk tie breaker on ordering).
>>
>> It's got me stumped. I can solve any number of simpler problems just not 
>> his generic one (yet). 
>>
>> Ideally I'd not build a list of all objects (waste of memory with large 
>> collections), and look for my thing in the list and then pick out the next 
>> or prior. 
>>
>> I'd ideally like to fetch it in one query returning the one Thing, or if 
>> not possible no worse than returning all Things on side of it and picking 
>> off the first or last respectively (even that's kludgy IMHO).
>>
>> I'm using postgresql and I found a related question here:
>>
>> 
>> https://dba.stackexchange.com/questions/53862/select-next-and-previous-rows
>>
>> but would rather stick with the ORM and not even explore SQL (just took a 
>> peak to see SQL can be constructed to do it I guess, as if not, the ORM 
>> sure won't have a good way of doing it methinks).
>>
>> I'd have thought this a sufficiently common use case but am perhaps wrong 
>> there, with most sites exploiting simple orderings (like date_time or 
>> creation say). But I want to build a generic solution that works on any 
>> model I write, so I can walk through the objects in the order specified by 
>> ordering, without building a list of all of them. In short I want to solve 
>> this problem, not reframe the problem or work around it ;-).
>>
>> Regards,
>>
>> Bernd.
>>
>> -- 
>> 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/751c367c-d5e9-e06b-8f5c-82054f11a9ab%40gmail.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *Julio Biason*, Sofware Engineer
> *AZION*  |  Deliver. Accelerate. Protect.
> Office: +55 51 3083 8101  |  Mobile: +55 51 *99907 0554*
>

-- 
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 

Re: Fetching next and/or prior objects given an arbitrary ordering

2018-02-28 Thread Bernd Wechner
Julio,

Thanks for giving it some though. But I think you misread me a little. I am 
using the get() only to illustrate that the precondition is, I have a 
single object. The goal then is find a neighboring object (as defined by 
the ordering in the model).

Yes indeed, a filter is the first and primary candidate for achieving that, 
but can you write one that respects an abritrary ordering involving 
multiple fields, as I exemplified with:

class Thing(models.Model):
 field1 = ...
 field2 = ...
 field2 = ...
 class Meta:
 ordering = ['field1', '-field2', 'field3']

Also consider that the ordering thus specified does not stipulate 
uniqueness in any way, that is many neighboring things in an ordered list 
may have identical values of field1, field2 and field3. 

I'm not sure how Django sorts those ties, but imagine it either defers to 
the underlying database engine (i.e. uses the sort simply to generate an 
ORDER BY clause in the SQL for example in the above case:

ORDER BY field1 ASC, field2 DESC, field3 ASC

and lets the underlying database engine define how ties are ordered. Or it 
could add a pk tie breaker to the end. Matters little, the problem remains: 
how to find neighbors given an arbitrary ordering and ties.

Can you write a filter clause to do that? I'm curious on that front. 

It's easy of course with one sort field with unique values collapsing to an 
__gt or __lt filter folllowed by first() or last() respectively (not sure 
that injects a LIMIT clause into the SQL or collects a list and then creams 
one element from it - I'll test a little I think). 

In the mean time, I still feel this has to be a fairly standard use case. 
It's about browsing objects in a table one by one, with a next and previous 
button given an ordering specified in the model and no guarantee of 
uniqueness on the (sort keys).

Regards,

Bernd.

On Thursday, 1 March 2018 00:58:58 UTC+11, Julio Biason wrote:
>
> Hi Bernd,
>
> Well, the thing with `get()` is that it will return only one object. What 
> you're looking for is `filter()`.
>
> Say, you want all the things that have an ID after a certain value. So you 
> get `list_of_things = Things.objects.filter(pk__gte=...)`. Now it'll return 
> the list, with all elements after the one you asked.
>
> If you want the previous and next, you can do `list_of_previous = 
> Things.objects.filter(pk__lt=...).limit(1)` and `list_of_next = 
> Things.objects.filter(pk__gt).limit(1)`.
>
> Or something like that ;P
>
> On Wed, Feb 28, 2018 at 8:56 AM, Bernd Wechner  > wrote:
>
>> I'm a bit stumped on this. Given an arbitrary ordering as specified by 
>> the ordering meta option:
>>
>> https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering
>>
>> for example:
>>
>> class Thing(models.Model):
>> field1 = ...
>> field2 = ...
>> field2 = ...
>> class Meta:
>> ordering = ['field1', '-field2', 'field3']
>>
>> given an instant of Thing:
>>
>> thing = Thing.objects.get(pk=...)
>>
>> how can I get the next Thing after that one, and/or the prior Thing 
>> before that one as they appear on the sorted list of Things.
>>
>> It's got me stumped as I can't think of an easy way to build a filter 
>> even with Q object for an arbitrary ordering given there can be multiple 
>> fields in ordering and multiple Things can have the same ordering list 
>> (i.e. there can be ties - that Django must resolve either arbitrarily or 
>> with an implicit pk tie breaker on ordering).
>>
>> It's got me stumped. I can solve any number of simpler problems just not 
>> his generic one (yet). 
>>
>> Ideally I'd not build a list of all objects (waste of memory with large 
>> collections), and look for my thing in the list and then pick out the next 
>> or prior. 
>>
>> I'd ideally like to fetch it in one query returning the one Thing, or if 
>> not possible no worse than returning all Things on side of it and picking 
>> off the first or last respectively (even that's kludgy IMHO).
>>
>> I'm using postgresql and I found a related question here:
>>
>> 
>> https://dba.stackexchange.com/questions/53862/select-next-and-previous-rows
>>
>> but would rather stick with the ORM and not even explore SQL (just took a 
>> peak to see SQL can be constructed to do it I guess, as if not, the ORM 
>> sure won't have a good way of doing it methinks).
>>
>> I'd have thought this a sufficiently common use case but am perhaps wrong 
>> there, with most sites exploiting simple orderings (like date_time or 
>> creation say). But I want to build a generic solution that works on any 
>> model I write, so I can walk through the objects in the order specified by 
>> ordering, without building a list of all of them. In short I want to solve 
>> this problem, not reframe the problem or work around it ;-).
>>
>> Regards,
>>
>> Bernd.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To 

Re: When do I need a new app within the site?

2018-02-28 Thread Mike Dewhirst

On 1/03/2018 4:46 AM, Karol Bujaček wrote:



On 02/22/2018 09:44 AM, Cictani wrote:

Hi,

I'm just beginning developing a new app(s) and I'm wondering when I 
need to add a new app. if one app uses models from another app is 
that a hint that these two apps are acutally one app or is this still 
ok in terms of good design?


Let's say I have a customer app (with customer models, admins etc) 
and a booking app which of course uses the customer model. Would it 
be good to have two apps or would it be actually only a booking app 
which includes all the models, logic etc from the customer app?


Thanks in advance

Andreas



Hello Andreas,

This issue bothers me too. For me, at the beginning it looks 
reasonable to create two (or more) different apps, but sooner or 
later, I’ve created a huge mess with too many dependencies between 
these apps. So, sometimes I feel that separating whole application is 
not the best idea. Obviously, there should be many lines of code which 
can/may/should be shared (= reusable app), but I think that almost 
always I need to make some customizations, add some ‘custom logic’ 
into views inside these apps... I don’t know how to grasp Django’s 
architecture, I feel that I’m missing something, that there should be 
something different than model & view & template.


I've recently tried to read mentioned Two scoops of Django book, but 
it doesn't help me with this. (Or I didn't spend too much time reading 
it).



Best regards,
Karol




For me, it is relatively easy. When you think of an entire project and 
draw it out on paper with boxes and lines you can see where the separate 
portions naturally fall.


Some things (nearly) always exist in (nearly) all projects. For example, 
users and user related items like profiles. For me, that means a 
separate app. Likewise (for me) I keep companies in a separate app. 
Licensed relationships between companies (for me) also go in the company 
app.


I don't necessarily try to make them re-usable right away. Working on my 
second project I just copied portions of the first and tweaked them as 
necessary. If that starts to bother me in future I might rework one or 
two apps so they become re-usable and supremely elegant. Maybe.


The idea is to become comfortable putting "from company 
importAddress,Company, Division, Phone" and just use them without 
thinking in your views, unit tests or other portions of your project 
where they might be needed. At least I don't have to scratch my head and 
try to remember where Address is defined. Of course it belongs in the 
company app alongside Phone and Division.


One of my projects has an enormous app with 40 models. I tried to 
separate them into two apps but my inexperience caused circular import 
problems. That forced me to keep them all together. In hindsight keeping 
them together was the right thing to do because those 40 models are all 
in the same brainspace.


I also have a "common" app to contain bits and pieces like utilities, 
generic template tags, exceptions imported from various places so I can 
always say in my code everywhere "from common.exceptions import 
ThisErrorOrThat". My common app doesn't have any models.


The bottom line is that you need to be comfortable in your own 
brainspace. If you can think about slicing off the easy bits into 
separate small apps it will leave the main game slightly more simple. 
And that is always good!


Cheers

Mike

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5c813349-89d9-9b39-1cb0-0179d934562a%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Upgrade django from 1.8 to 1.9 - issue

2018-02-28 Thread Jani Tiainen
Hi.

In your app __init__.py you import signals which in turn imports User model.


You can't do that any more.

Correct way to register signal handlers is to use app config ready.

See
https://docs.djangoproject.com/en/1.9/topics/signals/#connecting-receiver-functions

And section "where this code should live?".


28.2.2018 7.52 ip. "OliveTree"  kirjoitti:

I am upgrading from django 1.8.4 to 1.9.13. I installed django 1.9.3 and my
application stops working, it displays the following error:


Unhandled exception in thread started by .wrapper at 0x7effd13cbbf8>
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/utils/autoreload.py",
line 226, in wrapper
fn(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/django/core/
management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
  File "/usr/local/lib/python3.4/dist-packages/django/utils/autoreload.py",
line 249, in raise_last_exception
six.reraise(*_exception)
  File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line
685, in reraise
raise value.with_traceback(tb)
  File "/usr/local/lib/python3.4/dist-packages/django/utils/autoreload.py",
line 226, in wrapper
fn(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line
18, in setup
apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py",
line 85, in populate
app_config = AppConfig.create(entry)
  File "/usr/local/lib/python3.4/dist-packages/django/apps/config.py", line
90, in create
module = import_module(entry)
  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in
import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 2254, in _gcd_import
  File "", line 2237, in _find_and_load
  File "", line 2226, in
_find_and_load_unlocked
  File "", line 1200, in _load_unlocked
  File "", line 1129, in _exec
  File "", line 1471, in exec_module
  File "", line 321, in
_call_with_frames_removed
  File "/home/me/work/test_upgrade_django_to_1_11/be/myapp/__init__.py",
line 1, in 
import myapp.signals
  File "/home/me/work/test_upgrade_django_to_1_11/be/myapp/signals.py",
line 6, in 
from django.contrib.auth.models import User
  File "/usr/local/lib/python3.4/dist-packages/django/contrib/auth/models.py",
line 4, in 
from django.contrib.auth.base_user import AbstractBaseUser,
BaseUserManager
  File 
"/usr/local/lib/python3.4/dist-packages/django/contrib/auth/base_user.py",
line 49, in 
class AbstractBaseUser(models.Model):
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py",
line 94, in __new__
app_config = apps.get_containing_app_config(module)
  File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py",
line 239, in get_containing_app_config
self.check_apps_ready()
  File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py",
line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

In my setting I have:
(...)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'myapp',
#'debug_toolbar',
'django_extensions',
'corsheaders',
'watson',
'raven.contrib.django.raven_compat',
#'django.contrib.admindocs',
'django_mailbox',
'django.contrib.postgres', )
(...)

I'm using python3.4 and postgresql9.3

-- 
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/45a9eef2-abea-4bcc-b4e9-5f735ed1e4c7%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/CAHn91oe4OKhUyG__2DM8Ug-MHk5qxG9X%2BUdcAtR%2B8cXVOMzynQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trying to create a CBV that allows user to copy a record

2018-02-28 Thread Dylan Reinhold
Use the get_inital method.

def get_initial(self):
initial = super(MyCreateView, self).get_initial()
initial['name'] = 'Testing'
return initial

Dylan



On Wed, Feb 28, 2018 at 9:42 AM, Alexander Joseph <
alexander.v.jos...@gmail.com> wrote:

> I'd like to create a CBV to allow users to copy a record, except for item
> specific information. - I'm making a fixed assets app and if there are 2 of
> the same laptop I'd like the user to be able to make one record in the
> database, then copy it minus the serial number and asset tag number which
> would be the only info the user would have to fill in to copy that laptop.
>
> Is there a way to do this by modifying the CreateView somehow? 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/e4c25ff6-9e6e-4e5d-898a-f6d977f9badc%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/CAHtg44ArLW5ZnWOTDZioO-YUm3vaOAfA0NDKn4U6dfLzmwWxhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django-channels: WebSocketBridge options

2018-02-28 Thread Andrew Godwin
Hi Nicolas,

It's likely just an oversight in the coding. We're actually in the process
of removing official support for that JavaScript code as we have nobody to
maintain it, so I suggest you either clone it and modify it yourself or use
ReconnectingWebSocket directly.

Andrew

On Wed, Feb 28, 2018 at 9:30 AM, nferrari  wrote:

> Hello,
>
> It seems that it is not possible to pass options to ReconnectingWebsocket
> through WebSocketBridge. I'd like to do able to do so, like it's possible
> with ReconnectingWebsocket
> :
>
> var webSocketBridge = new channels.WebSocketBridge({maxRetries: 5});
>
> or
>
> var webSocketBridge = new channels.WebSocketBridge();
> webSocketBridge.maxRetries = 5;
>
> Did I miss something or is it a conception choice?
>
> Nicolas
>
> --
> 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/935cd6f7-ac2e-4e7a-be04-6462bd4e2a3f%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/CAFwN1uoSckj7-wwbKEMFTpqc4xr%3DeOai%2BmvsRbdEMVBAb1_2VA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help needed - new very first django App

2018-02-28 Thread Kasper Laudrup

Hi Jayaram,

On 2018-02-28 15:45, Jayaram Namburaj wrote:


When running the url http://127.0.0.1:8000/myapp/exRenderDict/ output 
doesn't display the values which is from the for loop.


You named your list 'MyListArg' not 'mylist' in the dictionary you 
passed to the render function.


Try changing this:

{% for val in mylist %}

To:

{% for val in MyListArg %}

That should hopefully fix it. I haven't tested it though.

Kind regards,

Kasper Laudrup

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/97649c53-b93c-2c3a-a2e6-95df7cc0b106%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Upgrade django from 1.8 to 1.9 - issue

2018-02-28 Thread OliveTree
I am upgrading from django 1.8.4 to 1.9.13. I installed django 1.9.3 and my 
application stops working, it displays the following error:


Unhandled exception in thread started by .wrapper at 0x7effd13cbbf8>
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/utils/autoreload.py", 
line 226, in wrapper
fn(*args, **kwargs)
  File 
"/usr/local/lib/python3.4/dist-packages/django/core/management/commands/runserver.py",
 
line 109, in inner_run
autoreload.raise_last_exception()
  File "/usr/local/lib/python3.4/dist-packages/django/utils/autoreload.py", 
line 249, in raise_last_exception
six.reraise(*_exception)
  File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 
685, in reraise
raise value.with_traceback(tb)
  File "/usr/local/lib/python3.4/dist-packages/django/utils/autoreload.py", 
line 226, in wrapper
fn(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 
18, in setup
apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", 
line 85, in populate
app_config = AppConfig.create(entry)
  File "/usr/local/lib/python3.4/dist-packages/django/apps/config.py", line 
90, in create
module = import_module(entry)
  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in 
import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 2254, in _gcd_import
  File "", line 2237, in _find_and_load
  File "", line 2226, in 
_find_and_load_unlocked
  File "", line 1200, in _load_unlocked
  File "", line 1129, in _exec
  File "", line 1471, in exec_module
  File "", line 321, in 
_call_with_frames_removed
  File "/home/me/work/test_upgrade_django_to_1_11/be/myapp/__init__.py", 
line 1, in 
import myapp.signals
  File "/home/me/work/test_upgrade_django_to_1_11/be/myapp/signals.py", 
line 6, in 
from django.contrib.auth.models import User
  File 
"/usr/local/lib/python3.4/dist-packages/django/contrib/auth/models.py", 
line 4, in 
from django.contrib.auth.base_user import AbstractBaseUser, 
BaseUserManager
  File 
"/usr/local/lib/python3.4/dist-packages/django/contrib/auth/base_user.py", 
line 49, in 
class AbstractBaseUser(models.Model):
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py", 
line 94, in __new__
app_config = apps.get_containing_app_config(module)
  File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", 
line 239, in get_containing_app_config
self.check_apps_ready()
  File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", 
line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

In my setting I have:
(...)
INSTALLED_APPS = ( 
'django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.sites', 
'django.contrib.messages', 
'django.contrib.staticfiles', 
'django.contrib.admin', 
'myapp', 
#'debug_toolbar', 
'django_extensions', 
'corsheaders', 
'watson', 
'raven.contrib.django.raven_compat', 
#'django.contrib.admindocs', 
'django_mailbox', 
'django.contrib.postgres', )
(...)

I'm using python3.4 and postgresql9.3

-- 
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/45a9eef2-abea-4bcc-b4e9-5f735ed1e4c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: When do I need a new app within the site?

2018-02-28 Thread Karol Bujaček



On 02/22/2018 09:44 AM, Cictani wrote:

Hi,

I'm just beginning developing a new app(s) and I'm wondering when I 
need to add a new app. if one app uses models from another app is that 
a hint that these two apps are acutally one app or is this still ok in 
terms of good design?


Let's say I have a customer app (with customer models, admins etc) and 
a booking app which of course uses the customer model. Would it be 
good to have two apps or would it be actually only a booking app which 
includes all the models, logic etc from the customer app?


Thanks in advance

Andreas



Hello Andreas,

This issue bothers me too. For me, at the beginning it looks reasonable 
to create two (or more) different apps, but sooner or later, I’ve 
created a huge mess with too many dependencies between these apps. So, 
sometimes I feel that separating whole application is not the best idea. 
Obviously, there should be many lines of code which can/may/should be 
shared (= reusable app), but I think that almost always I need to make 
some customizations, add some ‘custom logic’ into views inside these 
apps... I don’t know how to grasp Django’s architecture, I feel that I’m 
missing something, that there should be something different than model & 
view & template.


I've recently tried to read mentioned Two scoops of Django book, but it 
doesn't help me with this. (Or I didn't spend too much time reading it).



Best regards,
Karol


--
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/1ad1fb6e-7392-6782-e5eb-12279d5ce4b1%40fossilgroup.net.
For more options, visit https://groups.google.com/d/optout.


Trying to create a CBV that allows user to copy a record

2018-02-28 Thread Alexander Joseph
I'd like to create a CBV to allow users to copy a record, except for item 
specific information. - I'm making a fixed assets app and if there are 2 of 
the same laptop I'd like the user to be able to make one record in the 
database, then copy it minus the serial number and asset tag number which 
would be the only info the user would have to fill in to copy that laptop.

Is there a way to do this by modifying the CreateView somehow? 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/e4c25ff6-9e6e-4e5d-898a-f6d977f9badc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django-channels: WebSocketBridge options

2018-02-28 Thread nferrari
Hello,

It seems that it is not possible to pass options to ReconnectingWebsocket 
through WebSocketBridge. I'd like to do able to do so, like it's possible 
with ReconnectingWebsocket 
:

var webSocketBridge = new channels.WebSocketBridge({maxRetries: 5});

or

var webSocketBridge = new channels.WebSocketBridge();
webSocketBridge.maxRetries = 5;

Did I miss something or is it a conception choice?

Nicolas

-- 
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/935cd6f7-ac2e-4e7a-be04-6462bd4e2a3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to access binary file which is outside project folder

2018-02-28 Thread Andréas Kühne
Hi,

You shouldn't be doing that at all. If you want the file to be accessable
you need to include it in your media folder in the project - that's per
design.

The way django (and all other frameworks) work is to make sure that only
the items present in the application should be allowed. Even if you COULD
use for example "file://home/andreas/file.pdf" as a link, it wouldn't work
on anything else but YOUR machine, because that points to YOUR harddrive
and nowhere else.

Regards,

Andréas

2018-02-28 14:36 GMT+01:00 sam kavuri :

> I am new to Django and trying to access binary file which is outside
> project folder and open it in the browser.
>
> When i try to do that it is saying Cross-Origin Request is blocked
> (Reason: CORS header 'Access-Control-Allow-Origin missing).
>
> Somebody, please help on this.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/e74586f4-4831-4779-bf98-4d36221bee57%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/CAK4qSCe9JVLg6VBBoY9Atp237KQ9Cohv1a_Lfc_qH9PpL3WxVA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: How to get Foreign Key Objects programmatically?

2018-02-28 Thread Matthew Pava
You may want to look at the model _meta API.
https://docs.djangoproject.com/en/2.0/ref/models/meta/

You are looking for a list of all the ForeignKeys, but you also probably want 
other relations such as OneToOne and ManyToMany.
You probably want something like the get_all_related_objects method:
https://docs.djangoproject.com/en/2.0/ref/models/meta/#migrating-from-the-old-api

The fields have an attribute called is_relation, one_to_one, and many_to_one.


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Rob Schneider
Sent: Tuesday, February 27, 2018 10:46 PM
To: django-users@googlegroups.com
Subject: Re: How to get Foreign Key Objects programmatically?

Still a mystery to me.

--rms


On 28 Feb 2018, at 03:22, Malik Rumi 
> wrote:
Did you ever find an answer? If so, do you mind sharing it? Thanks.

On Sunday, October 29, 2017 at 9:33:10 AM UTC-7, rmschne wrote:
I'm using Django as front end to a MySQL database. User interface is a terminal 
program, not a web site.

I've written a very simple generic function to edit the fields of one record of 
a Django "object".  It works fine for editing editable fields. User specifies 
which field, then is shown the current value, raw_input() for the new value, 
then save() the record.

For fields that connect to Foreign Keys, what I want to do is present to user a 
simple list of Foreign Key records, from which the user will pick the relevant 
ID.  I know, given a list and the ID, how to then edit the record by doing a 
Django get(id=ID) on the Foreign Key table.  What I'm having trouble doing is 
figuring how

1. Identify into a variable the name of the Foreign Key table/object
2. Then with that variable do a call to the relevant Foreign Key table, e.g. 
ForeignKeyTable.objects.all()

See code below for <===WHAT I DO NOT KNOW HOW TO DO IN CODE Below.  I think I 
need some Django function that gives me the foreign key table in some useable 
generic form.

Hope all this makes sense.

--rms

def EditDjangoObjectData(djangoobject,show=False,editonerecord=False):
"""
EditDjangoObjectData()
djangoojbect=a django object, e.g. a record in a table
"""
print "\nToDo Note: This routine not yet working on fields with foreign 
keys!"
changelist=[]
ok=True
while ok:
change=None
fields = [(f.name, f.editable) for f in 
djangoobject._meta.get_fields()]
if show:
print "\nfields:\n",fields
print "django object:\n",djangoobject
s="\nEditable Fields ('enter' to return): \n"
fieldlist=[]
for i in fields:
if i[1]:   # only for 'editable' fields
if i[0].lower() <> "id":
s=s+i[0]+", "
fieldlist.append(i[0])
s=s+"DELETE or '?'"
fieldok=False
while not fieldok:
fieldtochange=raw_input("Enter field name to change:\n"+s+": ")
if not fieldtochange:
return None
elif fieldtochange.upper()=="DELETE":
ans=raw_input("...Confirm DELETE by typing 'DELETE': ")
try:
if ans=="DELETE":
rtn=djangoobject.delete()
print "Deleted. ",rtn
return rtn
except:
print "***DELETE Failed.",sys.exc_info()[0]
ans=raw_input("Press 'Enter' to continue ... ")
elif fieldtochange=="?":
PrintObjectDetails(djangoobject)
elif fieldtochange in fieldlist:
fieldok=True
else:
print "\nError. ",fieldtochange,"is not in list. Try again."
print "Current Value of Field to 
Change:",fieldtochange,"is:",getattr(djangoobject, fieldtochange)
**
** In here add some code to show a list of the foreign key records for user to 
select, e.g. ID, Description,
**for r in ForeignKey.objects.all():   <== WHAT I DO NOT KNOW HOW TO DO IN CODE.
**print i.id, i.description
**ID=raw_input("Enter ID:)
**foreignkeyobject=ForeignKey.objects.get(id=ID)<== WHAT I DO NOT KNOW HOW 
TO DO IN CODE.
** ... then put that object into the relevant field
newvalue=raw_input("Enter New Value: ")
change="changed ["+fieldtochange+"]"
print "\nTo Save   :",djangoobject
print "The Change:",change,"to",newvalue
if not newvalue:
return None
elif newvalue.lower()=="none":
newvalue=None
elif newvalue.lower()=="true":
newvalue==True
elif newvalue.lower()=="false":
newvalue=False
setattr(djangoobject, fieldtochange, newvalue)
try:
djangoobject.save()
print ": Success. Saved:",change,"to",newvalue
print ": New Object:",djangoobject
changelist.append(change)
 

Re: Why doesn't Django support managing Raw SQL changes using migration system like models

2018-02-28 Thread Julio Biason
Hi Cmp,

Well, Django has to be database agnostic for things to work with any
database. If raw sql is allowed, how do you can be sure it will work with
any database?

So far, you mentioned a bunch of PostreSQL things. But what if, tomorrow,
some higher ups decided that support is required and buy Oracle (because
higher ups usually aren't that smart). How things will work? How do you
make sure your raw SQL commands will work? (IIRC, there are differences in
SQL/DML between Oracle and MySQL).

The biggest problem I see is that you're using triggers. Django knows
nothing about them and since you're giving the database control to Django
(via its migrations and querysets), you should relegate all the things to
Django. And yes, there are drawbacks on that too, but still, everything
should be one single place -- and if you need other systems to add data to
your database, you should provide them with an API instead of letting them
add directly to the database.

The biggest problem I see on your solution, is that your giving powers over
your data to two different things -- Django and the database via triggers
-- and that's the first step into mess.

PS: 76 migrations is still nothing. I worked with databases with 150+
migrations, and nobody cared about what the migrations did, because the
models -- in their current, up-to-date form -- is the canonical
representation of the data. All those 150+ migrations were just the way to
reach the current state.

On Tue, Feb 27, 2018 at 8:53 PM, cmp  wrote:

> I have an problem that I wanted to solve recently using a Postgres Trigger
> + Procedure that I do not want to do via Signals or within Python itself.
>
> I want to make a log which when an entry is created the result is applied
> to a row. We need the log to be the source of truth and I don't want to
> write a whole async system using something like Kafka or whatever everyone
> recommends.
>
> The issue here is that I need to iterate on the procedure which updates
> the rows as features come along and make it easy for other developers to
> find/read/etc.
>
> Django only allows storing things like this as RawSql migration commands
> inside the migrations folder but this App already has 76 migrations and I
> think it's probably unreasonable for me to assume a normal django developer
> will think to read all those migrations without running in to some problem
> with my triggers. Not to mention the main block of sql will need to be copy
> and pasted between changes to new migrations... etc.
>
> This seems like something the migration system should support somehow.
>
> I found a package which seems to do this, but it appears unmaintained
> (little to no activity): https://github.com/klichukb/django-migrate-sql
>
> I think it'd be a nice feature for Django to support maintaining a set of
> Raw SQL via the migration system so more advanced features of databases can
> be used.
>
> For instance in Postgres setting up other things like full text search and
> special search indexes were difficult in 1.8. I realize it's easier since
> 1.10 to add a full text search index, but adding that feature is much more
> difficult than the RawSQL migrations we did to implement adding the index
> before.
>
> Making it easy to manage triggers and procedures via the migration system
> is very difficult, but I think supporting RawSQL items which are managed
> via migrations would be relatively easy to implement and add a lot of value.
>
> I'm posting this for two reasons: 1) I think it's a good idea and 2) to
> let others show me where I'm missing something or why this wouldn't be a
> good fit for Django.
>
> --
> 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/8043d044-3f7c-4bd2-bdc4-c504faf5120b%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

-- 
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 

Re: Fetching next and/or prior objects given an arbitrary ordering

2018-02-28 Thread Julio Biason
Hi Bernd,

Well, the thing with `get()` is that it will return only one object. What
you're looking for is `filter()`.

Say, you want all the things that have an ID after a certain value. So you
get `list_of_things = Things.objects.filter(pk__gte=...)`. Now it'll return
the list, with all elements after the one you asked.

If you want the previous and next, you can do `list_of_previous =
Things.objects.filter(pk__lt=...).limit(1)` and `list_of_next =
Things.objects.filter(pk__gt).limit(1)`.

Or something like that ;P

On Wed, Feb 28, 2018 at 8:56 AM, Bernd Wechner 
wrote:

> I'm a bit stumped on this. Given an arbitrary ordering as specified by the
> ordering meta option:
>
> https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering
>
> for example:
>
> class Thing(models.Model):
> field1 = ...
> field2 = ...
> field2 = ...
> class Meta:
> ordering = ['field1', '-field2', 'field3']
>
> given an instant of Thing:
>
> thing = Thing.objects.get(pk=...)
>
> how can I get the next Thing after that one, and/or the prior Thing before
> that one as they appear on the sorted list of Things.
>
> It's got me stumped as I can't think of an easy way to build a filter even
> with Q object for an arbitrary ordering given there can be multiple fields
> in ordering and multiple Things can have the same ordering list (i.e. there
> can be ties - that Django must resolve either arbitrarily or with an
> implicit pk tie breaker on ordering).
>
> It's got me stumped. I can solve any number of simpler problems just not
> his generic one (yet).
>
> Ideally I'd not build a list of all objects (waste of memory with large
> collections), and look for my thing in the list and then pick out the next
> or prior.
>
> I'd ideally like to fetch it in one query returning the one Thing, or if
> not possible no worse than returning all Things on side of it and picking
> off the first or last respectively (even that's kludgy IMHO).
>
> I'm using postgresql and I found a related question here:
>
> https://dba.stackexchange.com/questions/53862/select-next-
> and-previous-rows
>
> but would rather stick with the ORM and not even explore SQL (just took a
> peak to see SQL can be constructed to do it I guess, as if not, the ORM
> sure won't have a good way of doing it methinks).
>
> I'd have thought this a sufficiently common use case but am perhaps wrong
> there, with most sites exploiting simple orderings (like date_time or
> creation say). But I want to build a generic solution that works on any
> model I write, so I can walk through the objects in the order specified by
> ordering, without building a list of all of them. In short I want to solve
> this problem, not reframe the problem or work around it ;-).
>
> Regards,
>
> Bernd.
>
> --
> 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/751c367c-d5e9-e06b-8f5c-82054f11a9ab%40gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

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


how to access binary file which is outside project folder

2018-02-28 Thread sam kavuri
I am new to Django and trying to access binary file which is outside 
project folder and open it in the browser.

When i try to do that it is saying Cross-Origin Request is blocked (Reason: 
CORS header 'Access-Control-Allow-Origin missing).

Somebody, please help on this.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e74586f4-4831-4779-bf98-4d36221bee57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[digital envelope routines: EVP_MD_CTX_copy_ex] input not initialized

2018-02-28 Thread marek
I have proble with login to Django web admin. It produces bellow exception:

Internal Server Error: /adminlogin/
 Traceback (most recent call last):
   File 
"/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", 
line 41, in inner
 response = get_response(request)
   File 
"/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 
187, in _get_response
 response = self.process_exception_by_middleware(e, request)
   File 
"/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 
185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/views/decorators/cache.py", 
line 57, in _wrapped_view_func
 response = view_func(request, *args, **kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/contrib/admin/sites.py", 
line 393, in login
   File 
"/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 
68, in view
 return self.dispatch(request, *args, **kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 
67, in _wrapper
 return bound_func(*args, **kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/views/decorators/debug.py", 
line 76, in sensitive_post_parameters_wrapper
 return view(request, *args, **kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 
63, in bound_func
 return func.__get__(self, type(self))(*args2, **kwargs2)
   File 
"/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 
67, in _wrapper
 return bound_func(*args, **kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 
149, in _wrapped_view
response = view_func(request, *args, **kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 
63, in bound_func
 return func.__get__(self, type(self))(*args2, **kwargs2)
   File 
"/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 
67, in _wrapper
 return bound_func(*args, **kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/views/decorators/cache.py", 
line 57, in _wrapped_view_func
 response = view_func(request, *args, **kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 
63, in bound_func
 return func.__get__(self, type(self))(*args2, **kwargs2)
   File 
"/usr/local/lib/python3.6/site-packages/django/contrib/auth/views.py", line 
90, in dispatch
 return super(LoginView, self).dispatch(request, *args, **kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 
88, in dispatch
 return handler(request, *args, **kwargs)
   File 
"/usr/local/lib/python3.6/site-packages/django/views/generic/edit.py", line 
182, in post
 if form.is_valid():
   File "/usr/local/lib/python3.6/site-packages/django/forms/forms.py", 
line 183, in is_valid
 return self.is_bound and not self.errors
   File "/usr/local/lib/python3.6/site-packages/django/forms/forms.py", 
line 175, in errors
 self.full_clean()
   File "/usr/local/lib/python3.6/site-packages/django/forms/forms.py", 
line 385, in full_clean
 self._clean_form()
   File "/usr/local/lib/python3.6/site-packages/django/forms/forms.py", 
line 412, in _clean_form
 cleaned_data = self.clean()
   File 
"/usr/local/lib/python3.6/site-packages/django/contrib/auth/forms.py", line 
187, in clean
 self.user_cache = authenticate(self.request, username=username, 
password=password)
   File 
"/usr/local/lib/python3.6/site-packages/django/contrib/auth/__init__.py", 
line 70, in authenticate
 user = _authenticate_with_backend(backend, backend_path, request, 
credentials)
   File 
"/usr/local/lib/python3.6/site-packages/django/contrib/auth/__init__.py", 
line 116, in _authenticate_with_backend
 return backend.authenticate(*args, **credentials)
   File 
"/usr/local/lib/python3.6/site-packages/django/contrib/auth/backends.py", 
line 24, in authenticate
 if user.check_password(password) and self.user_can_authenticate(user):
   File 
"/usr/local/lib/python3.6/site-packages/django/contrib/auth/base_user.py", 
line 118, in check_password
 return check_password(raw_password, self.password, setter)
   File 
"/usr/local/lib/python3.6/site-packages/django/contrib/auth/hashers.py", 
line 52, in check_password
 is_correct = hasher.verify(password, encoded)
   File 
"/usr/local/lib/python3.6/site-packages/django/contrib/auth/hashers.py", 
line 265, in verify
 encoded_2 = self.encode(password, salt, int(iterations))
   File 
"/usr/local/lib/python3.6/site-packages/django/contrib/auth/hashers.py", 
line 258, in encode
 hash = pbkdf2(password, salt, iterations, digest=self.digest)
   File "/usr/local/lib/python3.6/site-packages/django/utils/crypto.py", 
line 140, in pbkdf2
 digest().name, password, salt, iterations, 

Deploying in hostgator VPS

2018-02-28 Thread Krishnaprasad Areekara
Can anyone shed some light on how to deploy django project in a hostgator
VPS including initial setup in the root? Where should I store static files?
And what all changes should I make while bringing the project into
production from Dev environment?

Thank you very 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/CAF558RqPxEv43%3DtiU6X%3D9mi5VOV1EHzXVPp%2BPeY45aDVB_zQug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: When do I need a new app within the site?

2018-02-28 Thread Julio Biason
Hi Andreas,

My rule of thumb is "does this works without the other?" Do your customer
app works without the booking app? Then they are two different apps, with
the second using the first as dependency.

But, then again, I had some people suggesting this wasn't good enough (for
deployment reasons, IIRC). I still use on my personal projects, though.

On Thu, Feb 22, 2018 at 5:44 AM, Cictani  wrote:

> Hi,
>
> I'm just beginning developing a new app(s) and I'm wondering when I need
> to add a new app. if one app uses models from another app is that a hint
> that these two apps are acutally one app or is this still ok in terms of
> good design?
>
> Let's say I have a customer app (with customer models, admins etc) and a
> booking app which of course uses the customer model. Would it be good to
> have two apps or would it be actually only a booking app which includes all
> the models, logic etc from the customer app?
>
> Thanks in advance
>
> Andreas
>
> --
> 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/65aac79d-064f-4142-96e0-4f9592cd6862%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

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


Fetching next and/or prior objects given an arbitrary ordering

2018-02-28 Thread Bernd Wechner
I'm a bit stumped on this. Given an arbitrary ordering as specified by 
the ordering meta option:


https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering

for example:

   class Thing(models.Model):
    field1 = ...
    field2 = ...
    field2 = ...
    class Meta:
    ordering = ['field1', '-field2', 'field3']

given an instant of Thing:

   thing = Thing.objects.get(pk=...)

how can I get the next Thing after that one, and/or the prior Thing 
before that one as they appear on the sorted list of Things.


It's got me stumped as I can't think of an easy way to build a filter 
even with Q object for an arbitrary ordering given there can be multiple 
fields in ordering and multiple Things can have the same ordering list 
(i.e. there can be ties - that Django must resolve either arbitrarily or 
with an implicit pk tie breaker on ordering).


It's got me stumped. I can solve any number of simpler problems just not 
his generic one (yet).


Ideally I'd not build a list of all objects (waste of memory with large 
collections), and look for my thing in the list and then pick out the 
next or prior.


I'd ideally like to fetch it in one query returning the one Thing, or if 
not possible no worse than returning all Things on side of it and 
picking off the first or last respectively (even that's kludgy IMHO).


I'm using postgresql and I found a related question here:

https://dba.stackexchange.com/questions/53862/select-next-and-previous-rows

but would rather stick with the ORM and not even explore SQL (just took 
a peak to see SQL can be constructed to do it I guess, as if not, the 
ORM sure won't have a good way of doing it methinks).


I'd have thought this a sufficiently common use case but am perhaps 
wrong there, with most sites exploiting simple orderings (like date_time 
or creation say). But I want to build a generic solution that works on 
any model I write, so I can walk through the objects in the order 
specified by ordering, without building a list of all of them. In short 
I want to solve this problem, not reframe the problem or work around it ;-).


Regards,

Bernd.

--
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/751c367c-d5e9-e06b-8f5c-82054f11a9ab%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django mathfiters

2018-02-28 Thread sum abiut
Thanks Peter.

cheers,

On Wed, Feb 28, 2018 at 5:05 PM, Peter of the Norse 
wrote:

> I would do
> {% with a=42 c=b.value|default_if_none:0}
>
> - Peter of the Norse
>
> On Feb 21, 2018, at 3:47 PM, Matthew Pava  wrote:
>
> And how are you checking if it’s None?  I would do it like this:
>
> {% if c %}
>
> {{ a|add:c }}
>
> {% else %}
>
>   {{ a }}
>
> {% endif %}
>
>
>
> *From:* django-users@googlegroups.com [mailto:django-users@
> googlegroups.com ] *On Behalf Of *sum abiut
> *Sent:* Wednesday, February 21, 2018 4:43 PM
> *To:* django-users@googlegroups.com
> *Subject:* Re: django mathfiters
>
>
>
> Thanks for your response. Yes the value was actually None. how to i
> display 42  instead of not displaying anything at all. I have try using the
> if statement to check for the value of c if its None i just display the
> value of a, and if is not None i add the values. But still its displaying
> nothing.
>
>
>
> Thanks
>
>
>
> On Thu, Feb 22, 2018 at 9:15 AM, Matthew Pava 
> wrote:
>
> Check the value of b.value.  Make sure it isn’t None.
>
>
>
> *From:* django-users@googlegroups.com [mailto:django-users@
> googlegroups.com] *On Behalf Of *sum abiut
> *Sent:* Wednesday, February 21, 2018 4:06 PM
> *To:* django-users@googlegroups.com
> *Subject:* django mathfiters
>
>
>
>
>
> Hi,
>
> How to you a zero in mathfilter
>
> for example, if the value of c is zero the total is not display. instead
> of displaying 42 it display nothing.
>
>
>
> {%for b in pay%}
>
> {% with a=42 c=b.value%}
>
>  {{ a|add:c }}
>
> {% endwith %}
>
>
> --
> 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/8C4DDEF6-9168-4181-B5DD-8E37AB487685%40Radio1190.org
> 
> .
>
> 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/CAPCf-y763dna8pOwE0d-9ZRZvhxHqMdBxV1TPEU0gmMGmicQ0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels 1.x

2018-02-28 Thread nferrari
Thank you Andrew for your answer!

Nicolas

On Wednesday, February 28, 2018 at 12:05:09 AM UTC+1, Andrew Godwin wrote:
>
> Yes, there is one session made per connection. They should expire and get 
> cleaned up like normal HTTP sessions if you run the session cleanup in 
> Django (or use backends that auto-cleanup)
>
> Andrew
>
> On Tue, Feb 27, 2018 at 11:00 AM, nferrari  > wrote:
>
>> Hello,
>>
>> I'm using django-channels for some months and I'm observing a behaviour 
>> for which I don't know if it's a normal one, or a misconfiguration from my 
>> side.
>> Here is my pretty simple consumer :
>>
>> # Connected to websocket.connect
>> @channel_session_user_from_http
>> def ws_task_connect(message):
>> if isinstance(message.user, AnonymousUser):
>> message.reply_channel.send({"close": True})
>> else:
>> # Accept connection
>> message.reply_channel.send({"accept": True})
>> # Add them to the right group
>> Group("task-%d" % message.user.pk).add(message.reply_channel)
>> refresh_current_tasks(message.user, send_if_empty=False)
>>
>> # Connected to websocket.disconnect
>> @enforce_ordering
>> @channel_session_user
>> def ws_task_disconnect(message):
>> Group("task-%d" % message.user.pk).discard(message.reply_channel)
>>
>> It does work but if my user does refresh the page, I see a new entry in 
>> the session table (django_session). In other terms, if my user browse 20 
>> different pages in his administration panel, I'll have 21 entries in the 
>> django_session table (1 session created by the native Django 
>> SessionMiddleware, 20 for every WebSocket created by browsing the 20 
>> pages). Is it normal or shouldn't this by reduced to 2 entries?
>>
>> For information, upgrading to django-channels 2 is not yet an option for 
>> this project.
>>
>> Kind regards,
>>
>> -- 
>> 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/160e0c3b-c74e-4683-acf6-a882716b9c5b%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/b1857c50-b1e7-48ef-b005-923f4b9795a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.