Additional column in Queryset with condition

2020-05-23 Thread Saurabh Adhikary
Hello ,

I need some advice / tips.

I am in a fix.
I have 2 databases & I want to join 2 tables of that. *As we know the
foreign key concept with 2 separate databases is not possible. *

Basically what I want is to add a custom column to a queryset and pass
the *current
row.name <http://row.name> *value to a function and that function will
return *location*. The return value should be saved for each row
individually. Each row will have different values. Currently, by annotate
the function is calling but :
1) * name* values are not getting passed
2) anything returned once is saved for the entire queryset.


*Constraint - change in models is difficult for my prod environment.*

database1.table1

database2.table1
*name* *rating*
*outlet* *location*
pizza hut 5
pizza-hut Mumbai
mc donalds 4
mc-donalds Washington

Now, I want to get *location *from database2.table1 and sort it with this
field .

What I have tried :
1 - queryset.annotate(loc=Value('abc', output_field=CharField())) and later
updating the queryset.  But the main queryset doesn't gets updated by each
row of the custom column. All the values gets updated by the same value.
2 - queryset.extra(select={'loc': myfunc('*name*')}) but here the column
values are not getting passed.
3 - queryset.extra(select={'loc': "select '*location*' from *database2*.table1
where outlet == %s"},select_params=('*name*',)) but here the column values
are not getting passed.


Kindly , if you can help find a solution by :
- handling the queryset in a better way
- writing a query like Count as that is working fine for a similar column
(although I know this works on Foreign key, but still if the logic is
helped how to write Count type of function I can write my own snippet)


Regards,
Saurabh Adhikary

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CABTrpg-rsBoyhpYMvCA_jk2E1%2BjMCy3vHPr97k1TCODkaRQd5Q%40mail.gmail.com.


Re: Additional column in Queryset with condition

2020-05-23 Thread Saurabh Adhikary
Hey Adam,

Thanks for your reply.

While writing this code I have found a bug . I shall start a new thread for
that then.

Thanks ,
Saurabh



On Sat, May 23, 2020, 8:11 PM Adam Johnson  wrote:

> Hi!
>
> I think you've found the wrong mailing list for this post. This mailing
> list is for discussing the development of Django itself, not for support
> using Django. This means the discussions of bugs and features in Django
> itself, rather than in your code using it. People on this list are unlikely
> to answer your support query with their limited time and energy.
>
> For support, please follow the "Getting Help" page:
> https://docs.djangoproject.com/en/3.0/faq/help/ . This will help you find
> people who are willing to support you, and to ask your question in a way
> that makes it easy for them to answer.
>
> Thanks for your understanding and all the best,
>
> Adam
>
> On Sat, 23 May 2020 at 09:37, Saurabh Adhikary 
> wrote:
>
>> Hello ,
>>
>> I need some advice / tips.
>>
>> I am in a fix.
>> I have 2 databases & I want to join 2 tables of that. *As we know the
>> foreign key concept with 2 separate databases is not possible. *
>>
>> Basically what I want is to add a custom column to a queryset and pass
>> the *current row.name <http://row.name> *value to a function and that
>> function will return *location*. The return value should be saved for
>> each row individually. Each row will have different values. Currently, by
>> annotate the function is calling but :
>> 1) * name* values are not getting passed
>> 2) anything returned once is saved for the entire queryset.
>>
>>
>> *Constraint - change in models is difficult for my prod environment.*
>>
>> database1.table1
>>
>> database2.table1
>> *name* *rating*
>> *outlet* *location*
>> pizza hut 5
>> pizza-hut Mumbai
>> mc donalds 4
>> mc-donalds Washington
>>
>> Now, I want to get *location *from database2.table1 and sort it with
>> this field .
>>
>> What I have tried :
>> 1 - queryset.annotate(loc=Value('abc', output_field=CharField())) and
>> later updating the queryset.  But the main queryset doesn't gets updated by
>> each row of the custom column. All the values gets updated by the same
>> value.
>> 2 - queryset.extra(select={'loc': myfunc('*name*')}) but here the column
>> values are not getting passed.
>> 3 - queryset.extra(select={'loc': "select '*location*' from 
>> *database2*.table1
>> where outlet == %s"},select_params=('*name*',)) but here the column
>> values are not getting passed.
>>
>>
>> Kindly , if you can help find a solution by :
>> - handling the queryset in a better way
>> - writing a query like Count as that is working fine for a similar column
>> (although I know this works on Foreign key, but still if the logic is
>> helped how to write Count type of function I can write my own snippet)
>>
>>
>> Regards,
>> Saurabh Adhikary
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-developers+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-developers/CABTrpg-rsBoyhpYMvCA_jk2E1%2BjMCy3vHPr97k1TCODkaRQd5Q%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-developers/CABTrpg-rsBoyhpYMvCA_jk2E1%2BjMCy3vHPr97k1TCODkaRQd5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Adam
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAMyDDM0A2ptt9%2Bo4PUymO3EXNN1B6Qs9gjADh9zTOZG1bcQxoA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-developers/CAMyDDM0A2ptt9%2Bo4PUymO3EXNN1B6Qs9gjADh9zTOZG1bcQxoA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CABTrpg_AEX6HY0jf8C_aKq1_Y45FxWwLYR0%2B00B7%2BDTfGdYcxw%40mail.gmail.com.


cannot use a string pattern on a bytes-like object

2019-05-31 Thread Saurabh Adhikary
Hello ,

I am upgrading my Django & Python from 1.8, 2.7 to 1.11,3.5.
For a models in TimeField I'm getting error in dateparse.py

Error -> cannot use a string pattern on a bytes-like object

Tried with datetime.now(), still not working.
Please help.

Regards,
Saurabh Adhikary

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