Re: Hi, i'm new to django i need some mini project which contain atleast 4 page for go through how it works

2016-08-31 Thread rajeshkmr9583
Hi,

   I have completed the tutorial my friend and by using the tutorial we are 
working with admin site only. I'm planning to work with my own HTML page. I 
have with worked Admin site but when i try to work with my own HTML page 
I'm not able to work. And now only started learning Django So i don't know 
all the concept from Django. Please help to achieve my target.

Thanks my friend,

On Wednesday, 31 August 2016 21:20:19 UTC+5:30, Abraham Varricatt wrote:
>
> This might be silly to ask but - can we assume you've completed the django 
> tutorial?
>
> On Monday, 29 August 2016 16:56:33 UTC+5:30, rajeshkmr9583 wrote:
>>
>> Hi, 
>>
>>  i'm new to Django i need some mini project which contain at least 4 
>> page for go through how it works..
>>
>> 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/6e0c989c-6b20-44c0-930a-67f3a0fac3f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Hi, i'm new to django i need some mini project which contain atleast 4 page for go through how it works

2016-08-31 Thread Rajesh Kumar
Hi,

   I have completed my frnd and by the tutorial we are working with admin
site i'm planning to work with my own html and css page. With i'll work
Admin site but when i try to work with my own html page i'm not able to
work.

Thanks my frnd,


On Wed, Aug 31, 2016 at 9:20 PM, 'Abraham Varricatt' via Django users <
django-users@googlegroups.com> wrote:

> This might be silly to ask but - can we assume you've completed the django
> tutorial?
>
> On Monday, 29 August 2016 16:56:33 UTC+5:30, rajeshkmr9583 wrote:
>>
>> Hi,
>>
>>  i'm new to Django i need some mini project which contain at least 4
>> page for go through how it works..
>>
>> 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/30c9a6ac-a9aa-4490-a636-c218c7fba254%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/CAOg8cE%2B1QFTJwvbpRqsEBFS95W-uEoQAiwKrnpgdbFCdQUt6Hw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Possible bug in AlterField migration with spatial_index

2016-08-31 Thread Tim Graham
That looks plausible. The place to patch would probably be 
https://github.com/django/django/blob/master/django/contrib/gis/db/backends/postgis/schema.py.
 
Could you create a Trac ticket and, if possible, a patch?

On Wednesday, August 31, 2016 at 6:33:23 PM UTC-4, Arjun Attam wrote:
>
> Hi,
>
> I have a model with a PointField, created with the spatial_index set as 
> True
> (the default value). Doing a \d table_name on postgresql revealed the index
> that was created, as expected.
>
> I updated the spatial_index to False and ran the migrations, which *did 
> not*
> drop the index in the db.
>
> I was also able to repro this with a PointField created with spatial_index 
> as
> False. When the field was updated to set spatial_index as True, an index 
> was
> not created in the database. Looks like AlterField migration is not working
> with PointField and spatial_index.
>
> I'm running Django 1.9.9 and PostgreSQL 9.5.1
>
> Best,
> Arjun
>

-- 
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/af64d1d9-69ea-4931-b646-5b4c364cee90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Possible bug in AlterField migration with spatial_index

2016-08-31 Thread Arjun Attam
Hi,

I have a model with a PointField, created with the spatial_index set as True
(the default value). Doing a \d table_name on postgresql revealed the index
that was created, as expected.

I updated the spatial_index to False and ran the migrations, which *did not*
drop the index in the db.

I was also able to repro this with a PointField created with spatial_index 
as
False. When the field was updated to set spatial_index as True, an index was
not created in the database. Looks like AlterField migration is not working
with PointField and spatial_index.

I'm running Django 1.9.9 and PostgreSQL 9.5.1

Best,
Arjun

-- 
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/715c3571-f17e-44ff-b933-72badf98e3ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Getting Start Django

2016-08-31 Thread jsroyal
 Thanks @Abraham for helping me out.
Now i getting run up. 

-- 
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/8d0462f4-cbfd-45fe-9a12-143fdf3ccfb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Getting Start Django

2016-08-31 Thread 'Abraham Varricatt' via Django users
It's nice that you are on Ubuntu. :)  Here is a quick and dirty way to get 
up to speed, (going to assume you will use python3)

# Installing virtualenv globally
$ sudo apt-get update
$ sudo apt-get install python3-pip
$ sudo pip3 install virtualenv

Once you have that done, navigate to an empty directory to create a new 
virtualenv folder, activate it, and install django!

$ mkdir test
$ cd test
$ virtualenv --python=python3 VENV
$ source VENV/bin/activate
(VENV)$ pip install django
(VENV)$ django-admin startproject mysite


...


(VENV)$ deactivate # to turn off the virutualenv, or just close the 
terminal session
$



Yours,
Abraham V.








On Wednesday, 31 August 2016 17:47:18 UTC+5:30, jsroyal wrote:
>
> Hello guys,
> I am newbie in Django and started learning with Standard Documentation 
> version: 
> *1.10.I *already Install Django 1.10 and Python 3.4 in Linux Ubuntu 15.04  
> But in first phage I got some problem 
> I type command 
>
> django-admin startproject mysite
>
> error:
> Cannot find installed version of python-django or python3-django
> Need some help to get out.
> Stay strong 
> JS
>

-- 
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/28f0e8f0-9183-42f9-97fd-365286f432d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Hi, i'm new to django i need some mini project which contain atleast 4 page for go through how it works

2016-08-31 Thread 'Abraham Varricatt' via Django users
This might be silly to ask but - can we assume you've completed the django 
tutorial?

On Monday, 29 August 2016 16:56:33 UTC+5:30, rajeshkmr9583 wrote:
>
> Hi, 
>
>  i'm new to Django i need some mini project which contain at least 4 
> page for go through how it works..
>
> 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/30c9a6ac-a9aa-4490-a636-c218c7fba254%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: cache.get_or_set : function name is misleading

2016-08-31 Thread florian


Le mercredi 31 août 2016 14:19:39 UTC+2, daniel.franca a écrit :
>
> But it's okay, isn't it?
> I mean, *add* is used to add the key if the key doesn't exist.
> *set* on the other hand, will set the value anyway.
>
> In the case of *get_or_set *the set should work like an *add *because 
> it'll be called only in case the key doesn't exist.
>
> Or am I missing something?
>

You're right on the expected behaviour. My point is that the function 
should have been named get_or_add since it is self explanatory. Reading the 
name get_or_set, i expect the function to first perform a get and then a 
set if the key is not there.

I'll try to see if i can submit something interesting for the doc.

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/529136a5-f5c7-48db-b002-3eb678d0857e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error: int() argument must be a string or a number, not 'SimpleLazyObject'

2016-08-31 Thread Shazia Nusrat
Following is the dispatch function:

 def dispatch(self, request, *args, **kwargs):
try:
user_check_id = self.request.session.get("user_checkout_id")
user_checkout = UserCheckout.objects.get(id=user_check_id)
except UserCheckout.DoesNotExist:
user_checkout = UserCheckout.objects.get(user=request.user)
except:
user_checkout = None

obj = self.get_object()
if obj.user == user_checkout and user_checkout is not None:
return super(OrderDetail, self).dispatch(request, *args,
**kwargs)
else:
raise Http404

On line 27 color is red. Usually the error related to SimpleLazyObject
means that it's not able to grab the field with reference. I don't know
what to replace it with.

On Wed, Aug 31, 2016 at 5:31 AM, Andromeda Yelton <
andromeda.yel...@gmail.com> wrote:

> I think the key line of the traceback is this -
> > File "C:\Users\Shazia\dd\src\orders\views.py" in dispatch
> >   27. user_checkout = UserCheckout.objects.get(user=
> request.user)
>
> And the error is being thrown during your redirect to /orders/4/ at the
> end of the post. What does your orders/views.py look like around line 27?
>
> Unrelated to this error, but I'm also wondering what happens in
> CheckoutFinalView if the paymethod is CashOnDelivery or CreditCard -
> neither of those branches of your if statement actually return any sort of
> http response.
>
> On Wed, Aug 31, 2016 at 7:27 AM, Shazia Nusrat 
> wrote:
>
>> Hi I am having this error while I am trying to delete session and cart by
>> IDs after order fulfillment.
>>
>> carts/views.py
>>
>> class CheckoutFinalView(CartOrderMixin, View):
>>> def post(self, request, *args, **kwargs):
>>> order = self.get_order()
>>> order_id = order.id
>>> print order_id
>>>
>>> pay_method = request.POST.get("paymethod")
>>> print pay_method
>>> order.save()
>>>
>>> if request.POST.get('paymethod') == "CashOnDelivery":
>>> order.mark_completed(order_id)
>>> messages.success(request, "Thank you for your order")
>>> del request.session["cart_id"]
>>> del request.session["order_id"]
>>> elif request.POST.get("paymethod") == 'CreditCard':
>>> order.mark_completed(order_id)
>>> messages.success(request, "Thank you for your order")
>>> del request.session['order_id']
>>> del request.session['cart_id']
>>> else:
>>> return redirect("order_detail", pk=order.pk)
>>>
>>
>> In my orders/models.py:
>>
>> order_id = models.CharField(max_length=20, null=True, blank=True)
>> paymethod = models.CharField(max_length=16, choices=CHOICES,
>> default='CashOnDelivery')
>>
>>
>> My orders/views.py:
>>
>> class CashOnDelivery(FormView):
>>> model = Order
>>> form_class = PaymentForm
>>> template_name = 'orders/payment_method.html'
>>> success_url = '/checkout/final'
>>>
>>> My orders/forms.py:
>>
>> class PaymentForm(forms.ModelForm):
>>> class Meta:
>>> model = Order
>>> fields = [
>>> 'paymethod'
>>> ]
>>>
>>
>> My carts/checkout.html:
>>
>> {% extends 'base.html' %}
>>> {% load crispy_forms_tags %}
>>> {% block content %}
>>>
>>> {% csrf_token %}
>>>  
>>> 
>>>
>>> {{ paymentform|crispy }}
>>>
>>>
>>>  Complete Order
>>> 
>>>
>>> 
>>> {% endblock %}.
>>>
>>
>> Finally my complete traceback:
>>
>> > Traceback:
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\core\handlers\base.py"
>> in get_response
>> >   132. response = wrapped_callback(request,
>> *callback_args, **callback_kwargs)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\views\generic\base.py"
>> in view
>> >   71. return self.dispatch(request, *args, **kwargs)
>> > File "C:\Users\Shazia\dd\src\orders\views.py" in dispatch
>> >   27. user_checkout = UserCheckout.objects.get(user=
>> request.user)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\manager.py"
>> in manager_method
>> >   127. return getattr(self.get_queryset(), name)(*args,
>> **kwargs)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py"
>> in get
>> >   325. clone = self.filter(*args, **kwargs)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py"
>> in filter
>> >   679. return self._filter_or_exclude(False, *args, **kwargs)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py"
>> in _filter_or_exclude
>> >   697. clone.query.add_q(Q(*args, **kwargs))
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
>> in add_q
>> >   1310. clause, require_inner = self._add_q(where_part,
>> self.used_aliases)
>> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
>> in _add_q
>> 

Re: Getting Start Django

2016-08-31 Thread ludovic coues
+1 on using pip
It will make your live easier

2016-08-31 15:15 GMT+02:00 Daniel França :
> I rather recommend you using a virtualenv and install using pip instead
> http://tutorial.djangogirls.org/en/django_installation/
>
> On Wed, 31 Aug 2016 at 14:50 jsroyal  wrote:
>>
>>
>> sudo apt-get install python-django-common
>> Through this command.
>>
>>
>>
>> --
>> 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/dacc07fe-48d4-491e-8757-aa167fd379f7%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/CACPst9%2BJoTk%3DwjX2DoBq0drS-zkUhWJwzH7L%2Bva3g5%3DeENk51Q%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

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


Re: Getting Start Django

2016-08-31 Thread Daniel França
I rather recommend you using a virtualenv and install using pip instead
http://tutorial.djangogirls.org/en/django_installation/

On Wed, 31 Aug 2016 at 14:50 jsroyal  wrote:

>
> sudo apt-get install python-django-common
> Through this command.
>
>
>
> --
> 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/dacc07fe-48d4-491e-8757-aa167fd379f7%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/CACPst9%2BJoTk%3DwjX2DoBq0drS-zkUhWJwzH7L%2Bva3g5%3DeENk51Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Getting Start Django

2016-08-31 Thread jsroyal

sudo apt-get install python-django-common
Through this command.

 

-- 
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/dacc07fe-48d4-491e-8757-aa167fd379f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error: int() argument must be a string or a number, not 'SimpleLazyObject'

2016-08-31 Thread Andromeda Yelton
I think the key line of the traceback is this -
> File "C:\Users\Shazia\dd\src\orders\views.py" in dispatch
>   27. user_checkout = UserCheckout.objects.get(user=
request.user)

And the error is being thrown during your redirect to /orders/4/ at the end
of the post. What does your orders/views.py look like around line 27?

Unrelated to this error, but I'm also wondering what happens in
CheckoutFinalView if the paymethod is CashOnDelivery or CreditCard -
neither of those branches of your if statement actually return any sort of
http response.

On Wed, Aug 31, 2016 at 7:27 AM, Shazia Nusrat 
wrote:

> Hi I am having this error while I am trying to delete session and cart by
> IDs after order fulfillment.
>
> carts/views.py
>
> class CheckoutFinalView(CartOrderMixin, View):
>> def post(self, request, *args, **kwargs):
>> order = self.get_order()
>> order_id = order.id
>> print order_id
>>
>> pay_method = request.POST.get("paymethod")
>> print pay_method
>> order.save()
>>
>> if request.POST.get('paymethod') == "CashOnDelivery":
>> order.mark_completed(order_id)
>> messages.success(request, "Thank you for your order")
>> del request.session["cart_id"]
>> del request.session["order_id"]
>> elif request.POST.get("paymethod") == 'CreditCard':
>> order.mark_completed(order_id)
>> messages.success(request, "Thank you for your order")
>> del request.session['order_id']
>> del request.session['cart_id']
>> else:
>> return redirect("order_detail", pk=order.pk)
>>
>
> In my orders/models.py:
>
> order_id = models.CharField(max_length=20, null=True, blank=True)
> paymethod = models.CharField(max_length=16, choices=CHOICES,
> default='CashOnDelivery')
>
>
> My orders/views.py:
>
> class CashOnDelivery(FormView):
>> model = Order
>> form_class = PaymentForm
>> template_name = 'orders/payment_method.html'
>> success_url = '/checkout/final'
>>
>> My orders/forms.py:
>
> class PaymentForm(forms.ModelForm):
>> class Meta:
>> model = Order
>> fields = [
>> 'paymethod'
>> ]
>>
>
> My carts/checkout.html:
>
> {% extends 'base.html' %}
>> {% load crispy_forms_tags %}
>> {% block content %}
>>
>> {% csrf_token %}
>>  
>> 
>>
>> {{ paymentform|crispy }}
>>
>>
>>  Complete Order
>> 
>>
>> 
>> {% endblock %}.
>>
>
> Finally my complete traceback:
>
> > Traceback:
> > File "C:\Users\Shazia\dd\lib\site-packages\django\core\handlers\base.py"
> in get_response
> >   132. response = wrapped_callback(request,
> *callback_args, **callback_kwargs)
> > File "C:\Users\Shazia\dd\lib\site-packages\django\views\generic\base.py"
> in view
> >   71. return self.dispatch(request, *args, **kwargs)
> > File "C:\Users\Shazia\dd\src\orders\views.py" in dispatch
> >   27. user_checkout = UserCheckout.objects.get(user=
> request.user)
> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\manager.py"
> in manager_method
> >   127. return getattr(self.get_queryset(), name)(*args,
> **kwargs)
> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py"
> in get
> >   325. clone = self.filter(*args, **kwargs)
> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py"
> in filter
> >   679. return self._filter_or_exclude(False, *args, **kwargs)
> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py"
> in _filter_or_exclude
> >   697. clone.query.add_q(Q(*args, **kwargs))
> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
> in add_q
> >   1310. clause, require_inner = self._add_q(where_part,
> self.used_aliases)
> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
> in _add_q
> >   1338. allow_joins=allow_joins,
> split_subq=split_subq,
> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
> in build_filter
> >   1200. lookups,
> value)
> > File 
> > "C:\Users\Shazia\dd\lib\site-packages\django\db\models\fields\related.py"
> in get_lookup_constraint
> >   1745. lookup_class(target.get_col(alias, source),
> val), AND)
> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\lookups.py"
> in __init__
> >   101. self.rhs = self.get_prep_lookup()
> > File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\lookups.py"
> in get_prep_lookup
> >   139. return 
> > self.lhs.output_field.get_prep_lookup(self.lookup_name,
> self.rhs)
> > File 
> > "C:\Users\Shazia\dd\lib\site-packages\django\db\models\fields\__init__.py"
> in get_prep_lookup
> >   727. return self.get_prep_value(value)
> > File 
> > 

Re: Getting Start Django

2016-08-31 Thread Daniel França
How did you install Django?

On Wed, 31 Aug 2016 at 14:17 jsroyal  wrote:

> Hello guys,
> I am newbie in Django and started learning with Standard Documentation
> version:
> *1.10.I *already Install Django 1.10 and Python 3.4 in Linux Ubuntu 15.04
> But in first phage I got some problem
> I type command
>
> django-admin startproject mysite
>
> error:
> Cannot find installed version of python-django or python3-django
> Need some help to get out.
> Stay strong
> JS
>
> --
> 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/2fc42b55-e9da-46cc-8762-06265deb6b43%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/CACPst9J4mqXfX4ywadcs7k6p8GxDPTzA1TjTQTukGdRDZumyfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: cache.get_or_set : function name is misleading

2016-08-31 Thread Daniel França
But it's okay, isn't it?
I mean, *add* is used to add the key if the key doesn't exist.
*set* on the other hand, will set the value anyway.

In the case of *get_or_set *the set should work like an *add *because it'll
be called only in case the key doesn't exist.

Or am I missing something?

On Wed, 31 Aug 2016 at 13:18 Tim Graham  wrote:

> You're welcome to submit a documentation patch to help clarify.
>
>
> On Wednesday, August 31, 2016 at 5:54:21 AM UTC-4, florian wrote:
>>
>> Hi,
>>
>> I wanted to refactor my code using cache.get_or_set instead of using
>> cache.get and then check for None and so on
>>
>> However, after a few tests, it seems that get_or_set does not work as
>> its name suggests: it is more get_or_add than get_or_set
>>
>> Looking at the source code, it indeed does a get, then a add, not a set.
>>
>> To my mind, the function name is misleading, even if after a careful
>> reading of the doc, it explains that the value is added (not set) if not
>> in the cache.
>>
>> I haven't found anything about this, so i may be the only one astonished
>> by the difference between function name and function main behaviour.
>> However, i think it's useful to live a comment about this for other devs.
>>
>> Cheers
>>
>> Florian
>>
> --
> 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/5b164103-dbeb-44c1-a014-24a31c1a5fcd%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/CACPst9K75DWcK0ZkyRrOWEgtn6D5UmboO3T5dZLB-Qi9R126EA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Getting Start Django

2016-08-31 Thread jsroyal
Hello guys,
I am newbie in Django and started learning with Standard Documentation 
version: 
*1.10.I *already Install Django 1.10 and Python 3.4 in Linux Ubuntu 15.04  
But in first phage I got some problem 
I type command 

django-admin startproject mysite

error:
Cannot find installed version of python-django or python3-django
Need some help to get out.
Stay strong 
JS

-- 
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/2fc42b55-e9da-46cc-8762-06265deb6b43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ti possible CommaSeparatedIpField

2016-08-31 Thread Gergely Polonkai
Hello,

although it is possible, I'd go with an IP field and generate a list of
them, comma separated, at run time. This will make it easier to search and
manage the list.

Best,

Gergely

On Wed, Aug 31, 2016, 00:29 Jorge Cadena  wrote:

> Hi
>
> I have a idea CommaSeparatedIpField, it possible ?
>
> this for validacion IP ACL list in FreeSWITCH.
>
> --
> 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/9d5d8359-ce30-41c8-8d88-2733b32ad76d%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/CACczBUJvNiyC7QZ1NFjYkx97i1tB7%3D7QKGwu49PVsfaWr%2BZg7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Error: int() argument must be a string or a number, not 'SimpleLazyObject'

2016-08-31 Thread Shazia Nusrat
Hi I am having this error while I am trying to delete session and cart by
IDs after order fulfillment.

carts/views.py

class CheckoutFinalView(CartOrderMixin, View):
> def post(self, request, *args, **kwargs):
> order = self.get_order()
> order_id = order.id
> print order_id
>
> pay_method = request.POST.get("paymethod")
> print pay_method
> order.save()
>
> if request.POST.get('paymethod') == "CashOnDelivery":
> order.mark_completed(order_id)
> messages.success(request, "Thank you for your order")
> del request.session["cart_id"]
> del request.session["order_id"]
> elif request.POST.get("paymethod") == 'CreditCard':
> order.mark_completed(order_id)
> messages.success(request, "Thank you for your order")
> del request.session['order_id']
> del request.session['cart_id']
> else:
> return redirect("order_detail", pk=order.pk)
>

In my orders/models.py:

order_id = models.CharField(max_length=20, null=True, blank=True)
paymethod = models.CharField(max_length=16, choices=CHOICES,
default='CashOnDelivery')


My orders/views.py:

class CashOnDelivery(FormView):
> model = Order
> form_class = PaymentForm
> template_name = 'orders/payment_method.html'
> success_url = '/checkout/final'
>
> My orders/forms.py:

class PaymentForm(forms.ModelForm):
> class Meta:
> model = Order
> fields = [
> 'paymethod'
> ]
>

My carts/checkout.html:

{% extends 'base.html' %}
> {% load crispy_forms_tags %}
> {% block content %}
>
> {% csrf_token %}
>  
> 
>
> {{ paymentform|crispy }}
>
>
>  Complete Order
> 
>
> 
> {% endblock %}.
>

Finally my complete traceback:

> Traceback:
> File "C:\Users\Shazia\dd\lib\site-packages\django\core\handlers\base.py"
in get_response
>   132. response = wrapped_callback(request,
*callback_args, **callback_kwargs)
> File "C:\Users\Shazia\dd\lib\site-packages\django\views\generic\base.py"
in view
>   71. return self.dispatch(request, *args, **kwargs)
> File "C:\Users\Shazia\dd\src\orders\views.py" in dispatch
>   27. user_checkout =
UserCheckout.objects.get(user=request.user)
> File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\manager.py"
in manager_method
>   127. return getattr(self.get_queryset(), name)(*args,
**kwargs)
> File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py" in
get
>   325. clone = self.filter(*args, **kwargs)
> File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py" in
filter
>   679. return self._filter_or_exclude(False, *args, **kwargs)
> File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\query.py" in
_filter_or_exclude
>   697. clone.query.add_q(Q(*args, **kwargs))
> File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
in add_q
>   1310. clause, require_inner = self._add_q(where_part,
self.used_aliases)
> File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
in _add_q
>   1338. allow_joins=allow_joins,
split_subq=split_subq,
> File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\sql\query.py"
in build_filter
>   1200. lookups,
value)
> File
"C:\Users\Shazia\dd\lib\site-packages\django\db\models\fields\related.py"
in get_lookup_constraint
>   1745. lookup_class(target.get_col(alias, source),
val), AND)
> File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\lookups.py"
in __init__
>   101. self.rhs = self.get_prep_lookup()
> File "C:\Users\Shazia\dd\lib\site-packages\django\db\models\lookups.py"
in get_prep_lookup
>   139. return
self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs)
> File
"C:\Users\Shazia\dd\lib\site-packages\django\db\models\fields\__init__.py"
in get_prep_lookup
>   727. return self.get_prep_value(value)
> File
"C:\Users\Shazia\dd\lib\site-packages\django\db\models\fields\__init__.py"
in get_prep_value
>   985. return int(value)
>
> Exception Type: TypeError at /orders/4/
> Exception Value: int() argument must be a string or a number, not
'SimpleLazyObject'

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


Re: get_available_name() got an unexpected keyword argument 'max_length'

2016-08-31 Thread manolo gomez
I thought that I've checked all my dependecies, and effectively I forget to 
update one of them. Now it's working, thank you very much.

El martes, 30 de agosto de 2016, 18:45:23 (UTC+2), Tim Graham escribió:
>
> You need to update your own code or one of your dependencies as per 
> https://docs.djangoproject.com/en/stable/releases/1.8/#support-for-the-max-length-argument-on-custom-storage-classes
> .
>
> If you follow 
> https://docs.djangoproject.com/en/stable/howto/upgrade-version/ with an 
> older version of Django (1.8 or 1.9), you should see a helpful deprecation 
> warning.
>
> On Tuesday, August 30, 2016 at 9:39:46 AM UTC-4, manolo gomez wrote:
>>
>> Hi,
>>
>>I've updated from django 1.8 to 1.10, and now when save a ImageFile 
>> I'm getting the next error:
>>   
>>get_available_name() got an unexpected keyword argument 'max_length'
>>
>>   
>> This is the end of the Traceback:
>> File "/home/dev/Documents/web/children/views/views.py" in post
>>
>>   73. ob.avatar.save(t[0], t[1])
>>
>>  File 
>> "/home/securekids/Documents/enviroments/dev/local/lib/python2.7/site-packages/django/db/models/fields/files.py"
>>  in save
>>   91. self.name = self.storage.save(name, content, 
>> max_length=self.field.max_length)
>>
>> File 
>> "/home/securekids/Documents/enviroments/dev/local/lib/python2.7/site-packages/django/core/files/storage.py"
>>  in save
>>   53. name = self.get_available_name(name, max_length=max_length)
>>
>>
>>   I've tried to remove  "max_length=max_length", and then it's working 
>> fine, but I don't like so much to touch the django core :)
>>   
>>Anyone can help me? 
>>
>

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


Re: cache.get_or_set : function name is misleading

2016-08-31 Thread Tim Graham
You're welcome to submit a documentation patch to help clarify.

On Wednesday, August 31, 2016 at 5:54:21 AM UTC-4, florian wrote:
>
> Hi, 
>
> I wanted to refactor my code using cache.get_or_set instead of using 
> cache.get and then check for None and so on 
>
> However, after a few tests, it seems that get_or_set does not work as 
> its name suggests: it is more get_or_add than get_or_set 
>
> Looking at the source code, it indeed does a get, then a add, not a set. 
>
> To my mind, the function name is misleading, even if after a careful 
> reading of the doc, it explains that the value is added (not set) if not 
> in the cache. 
>
> I haven't found anything about this, so i may be the only one astonished 
> by the difference between function name and function main behaviour. 
> However, i think it's useful to live a comment about this for other devs. 
>
> Cheers 
>
> Florian 
>

-- 
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/5b164103-dbeb-44c1-a014-24a31c1a5fcd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A tricky query in one to many relationship - atleast for me:)

2016-08-31 Thread Web Architect
Hi Michal,

Thanks for the solution. I tried the solution in a different way:

A.objects.annotate( 
max_date_created=Max('b__date_created')).filter(b__date_created=F('max_date_created'),
 
b__text='ABCD') 

Hope the above amounts to the same thing as you have suggested.

Thanks.


On Wednesday, August 31, 2016 at 1:48:38 PM UTC+5:30, Michal Petrucha wrote:
>
> On Tue, Aug 30, 2016 at 11:46:14PM -0700, Web Architect wrote: 
> > Hi Erik, 
> > 
> > I tried your solution but there are some issues: 
> > 
> > .filter(date_created=Max('a__b__date_created'))  - this is throwing 
> error 
> > saying not proper use of group function. 
> > 
> > If I remove the above, the result isn't correct where when I go through 
> > each 'a' in the result, associated latest B.text isn't always 'ABCD' - 
> if 
> > there are multiple instances of B associated with an instance of A and 
> one 
> > of the instances of B has text='ABCD' (might not be the latest 
> > date_created), that instance of B is also there in the query result. 
>
> Hmm, I haven't actually tried to run any code, but I'd try reordering 
> some of the method calls, and using an explcit field alias for the 
> annotation, which should let you then use an F() expression in 
> subsequent filters; something like this: 
>
> A.objects.filter( 
> b__in=B.objects 
> .annotate(max_date_created=Max('a__b__date_created')) 
> .filter(date_created=F('max_date_created'), text='ABCD') 
> ) 
>
> Good luck, 
>
> Michal 
>

-- 
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/88d20adc-6375-425c-88a5-870d0244471f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


cache.get_or_set : function name is misleading

2016-08-31 Thread Florian Iragne

Hi,

I wanted to refactor my code using cache.get_or_set instead of using 
cache.get and then check for None and so on


However, after a few tests, it seems that get_or_set does not work as 
its name suggests: it is more get_or_add than get_or_set


Looking at the source code, it indeed does a get, then a add, not a set.

To my mind, the function name is misleading, even if after a careful 
reading of the doc, it explains that the value is added (not set) if not 
in the cache.


I haven't found anything about this, so i may be the only one astonished 
by the difference between function name and function main behaviour. 
However, i think it's useful to live a comment about this for other devs.


Cheers

Florian

--
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/46cbd955-705d-2d52-e1db-a88a40b7c635%40iragne.fr.
For more options, visit https://groups.google.com/d/optout.


Re: How to create a database for my website in Django

2016-08-31 Thread ludovic coues
Hi jeff,

I would suggest you looking up the documentation on creating a
database [1] and the following section on how to connect to your
freshly created database from django.

When you get to creating your table, you might want to simply use
django's tools. One of the key feature for developer on tight schedule
is how it manage the database for you. Once it is connected, django
will read your models files, create migration data and update the
database schema accordingly.
All you have to do is running `python manage.py makemigrations` and
`python manage.py migrate`.

If you have any issue following the documentation, don't hesitate to
come back with more question.

If you are new to django, I suggest you do at least one django related
tutorial as suggested by Mudassar.
There is the official tutorial [2] of course, but django girls
tutorial [3] is more beginner friendly


[1] https://docs.djangoproject.com/en/1.10/ref/databases/#creating-your-database
[2] https://docs.djangoproject.com/en/1.10/intro/tutorial01/
[3] http://tutorial.djangogirls.org/en/

2016-08-31 0:23 GMT+02:00 Jeff Goes :
> I have little knowledge when it comes to the creation of databases. I would
> like to know if someone can help me set a database for my website step by
> step since I have a deadline due to next month to finish a project that
> requires that kind of knowledge. The idea is to input information on the
> website and save them into an internal database. I already have MySql and
> Sequel Pro installed but don't know how to link them to my website.
>
> I appreciate it.
>
> --
> 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/500d5d57-6c92-4f3e-947d-cfb5d74092d9%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

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


Re: ti possible CommaSeparatedIpField

2016-08-31 Thread ludovic coues
If you are asking if it is possible to create such field, the response
is yes, you can create such field.
Looking at the source of CommaSeparatedIntegerField, you can see it's
a simple CharField with a validate_comma_separated_integer_list
validator and a custom error message.

You could also have an IPAdress model and a manytomany field in the
model in place of CommaSeparatedIpField. As an added bonus, the
IPAddress model could have extra field like a description for the ip.


2016-08-31 0:29 GMT+02:00 Jorge Cadena :
> Hi
>
> I have a idea CommaSeparatedIpField, it possible ?
>
> this for validacion IP ACL list in FreeSWITCH.
>
> --
> 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/9d5d8359-ce30-41c8-8d88-2733b32ad76d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

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


Re: A tricky query in one to many relationship - atleast for me:)

2016-08-31 Thread Michal Petrucha
On Tue, Aug 30, 2016 at 11:46:14PM -0700, Web Architect wrote:
> Hi Erik,
> 
> I tried your solution but there are some issues:
> 
> .filter(date_created=Max('a__b__date_created'))  - this is throwing error 
> saying not proper use of group function.
> 
> If I remove the above, the result isn't correct where when I go through 
> each 'a' in the result, associated latest B.text isn't always 'ABCD' - if 
> there are multiple instances of B associated with an instance of A and one 
> of the instances of B has text='ABCD' (might not be the latest 
> date_created), that instance of B is also there in the query result.

Hmm, I haven't actually tried to run any code, but I'd try reordering
some of the method calls, and using an explcit field alias for the
annotation, which should let you then use an F() expression in
subsequent filters; something like this:

A.objects.filter( 
b__in=B.objects 
.annotate(max_date_created=Max('a__b__date_created')) 
.filter(date_created=F('max_date_created'), text='ABCD') 
) 

Good luck,

Michal

-- 
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/20160831081747.GF6601%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: A tricky query in one to many relationship - atleast for me:)

2016-08-31 Thread Web Architect
Hi Erik,

I tried your solution but there are some issues:

.filter(date_created=Max('a__b__date_created'))  - this is throwing error 
saying not proper use of group function.

If I remove the above, the result isn't correct where when I go through 
each 'a' in the result, associated latest B.text isn't always 'ABCD' - if 
there are multiple instances of B associated with an instance of A and one 
of the instances of B has text='ABCD' (might not be the latest 
date_created), that instance of B is also there in the query result.

Thanks.

On Tuesday, August 30, 2016 at 3:59:20 PM UTC+5:30, Erik Cederstrand wrote:
>
>
> > Den 30. aug. 2016 kl. 11.20 skrev Erik Cederstrand <
> erik+...@cederstrand.dk >: 
> > 
> > I'm not even sure that's possible to express in SQL, but it would 
> probably be quite convoluted if it is. Here's an easier-to-understand 
> solution: 
> > 
> > res = set() 
> > for b in 
> B.objects.all().select_related('a').annotate(Max('date_created')): 
> >if b.date_created != b.date_created__max: 
> >continue 
> >if b.text != 'ABCD': 
> >continue 
> >res.add(a) 
>
> I did some more experimenting. I think this actually does what you want: 
>
> res = [ 
> b.a for b in B.objects 
> .filter(date_created=Max('a__b__date_created')) 
> .annotate(Max('a__b__date_created')) 
> .filter(text='ABCD') 
> .select_related('a') 
> ] 
>
> which you can rewrite as: 
>
> A.objects.filter( 
> b__in=B.objects 
> .filter(date_created=Max('a__b__date_created')) 
> .annotate(Max('a__b__date_created')) 
> .filter(text='ABCD') 
> ) 
>
> Erik

-- 
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/13a40885-4cce-46af-ba50-368942608c37%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.