Ajax Call is sending empty request.POST or request.body

2017-03-31 Thread Camilo Torres
Hi.

The difference is explained here:
https://docs.djangoproject.com/en/1.10/ref/request-response/

You are sending the data in the ajax call as Jason (I suppose, from the content 
type), then in your view you should probably use request.body to read the json 
document.

I also noticed you are using a django form. In that case you can change your 
ajax call to send a form encoding content type and serialize the html form as 
the data. In your view you can then use your django form to process the data 
from request.POST.

-- 
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/d30946f0-6403-4549-91e9-43536c129df1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Would it be a good idea to build a IM app using django channels?

2017-03-31 Thread Vic Wei
I'm trying to build a django Instant Massage app, but I have some 
confusions,
My app should the following needs:
1.be able to communicate in real time with browser, iOS, and Android native 
apps.
2.one user can send messages to another user in private
3.users can chat in serval chat room at a time
4.once a message is sent, it should be push to target user in realtime.
5.has a retry mechanism to guarantee delivery and messages should store in 
db like mysql
Is django channels suite my requirements? Is there a limit amout of channel 
or is that what I need to do is create a group for each online user 
including ios and android ones?
What my thought is using redis to cache the messages and store in MySQL, 
use celery to handle message store and distribute.
Anyone could give some advices?


-- 
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/228be88c-4ca8-4b52-875c-eb361e534e57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 10.6 throws 'mbcs codec error' on Windows 10 machine in autoload.py

2017-03-31 Thread Владислав Котвицкий
I study Django too and my first lesson was be here
https://tutorial.djangogirls.org/en/
use virtualenv

С уважением, Владислав Котвицкий
г.Краснодар, +7(988)4112077

2017-03-29 12:28 GMT+03:00 Paul Rusu-Tibreanu :

> Hi to all,
>
> I am trying to get started with Django. So  installing Django through pip
> and following the tutorial on the project's website, I first created a
> "mysite" project and now try to run "
>
> python manage.py runserver". However, this gives me following error:
>
> C:\mysite>python manage.py runserver
> Traceback (most recent call last):
>   File "manage.py", line 22, in 
> execute_from_command_line(sys.argv)
>   File 
> "C:\Users\User\Anaconda3\lib\site-packages\django\core\management\__init__.py",
>  line 367, in execute_from_command_line
> utility.execute()
>   File 
> "C:\Users\User\Anaconda3\lib\site-packages\django\core\management\__init__.py",
>  line 359, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File 
> "C:\Users\User\Anaconda3\lib\site-packages\django\core\management\base.py", 
> line 294, in run_from_argv
> self.execute(*args, **cmd_options)
>   File 
> "C:\Users\User\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py",
>  line 58, in execute
> super(Command, self).execute(*args, **options)
>   File 
> "C:\Users\User\Anaconda3\lib\site-packages\django\core\management\base.py", 
> line 345, in execute
> output = self.handle(*args, **options)
>   File 
> "C:\Users\User\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py",
>  line 97, in handle
> self.run(**options)
>   File 
> "C:\Users\User\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py",
>  line 106, in run
> autoreload.main(self.inner_run, None, options)
>   File 
> "C:\Users\User\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 
> 333, in main
> reloader(wrapped_main_func, args, kwargs)
>   File 
> "C:\Users\User\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 
> 304, in python_reloader
> exit_code = restart_with_reloader()
>   File 
> "C:\Users\User\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 
> 290, in restart_with_reloader
> exit_code = os.spawnve(os.P_WAIT, sys.executable, args, new_environ)
> UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: 
> invalid character
>
>
> Does anyone know th ereason for this error and how to fix it?
>
> Thanks a lot.
>
> --
> 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/2269a709-c132-4935-85cb-6a59e2907a9d%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/CAGVCDGQJaPznhoicQBZbNXs0GGYfF3HH8xWyMugr52z1fAethw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Adding fields in model, migrating a sqlite.db in production...good idea?

2017-03-31 Thread kalinski
Hello,
I have a sqlite db that already holds important production data.
Well same time I am developing that application adding functions while I need 
them.
Well I know not exactly best practice.
Now I need to add two fields to a model (boolean and char),
I want to makemigrations, git add, git commit, git push
Is there any risk of loosing part of the sqlite database here?
Or can I just backup the sqlite file, try to migrate and all the data plus the 
new empty fields will be there?
If someone with better knowledge can just say "yes should be working"?
Many thanks!
Martin

-- 
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/d67d940b-b6ce-49f5-902a-aae14ed174d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding fields in model, migrating a sqlite.db in production...good idea?

2017-03-31 Thread ludovic coues
Make a copy of your sqlite file and try makemigration on your copy.
Everything should go smoothly. If that's the case, you can now use
your copy as your new production database.

As a side note, I don't think using an sqlite database is bad
practice. It make it super easy to backup your data.

2017-03-31 19:19 GMT+02:00 kalinski :
> Hello,
> I have a sqlite db that already holds important production data.
> Well same time I am developing that application adding functions while I need 
> them.
> Well I know not exactly best practice.
> Now I need to add two fields to a model (boolean and char),
> I want to makemigrations, git add, git commit, git push
> Is there any risk of loosing part of the sqlite database here?
> Or can I just backup the sqlite file, try to migrate and all the data plus 
> the new empty fields will be there?
> If someone with better knowledge can just say "yes should be working"?
> Many thanks!
> Martin
>
> --
> 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/d67d940b-b6ce-49f5-902a-aae14ed174d3%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%2BTZzS6BEhsw4WQtdMc8gY-Lt27xGWyPTDmMO2WxMAC6Y8g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding fields in model, migrating a sqlite.db in production...good idea?

2017-03-31 Thread kalinski
super thanks! i hoped for that answer!

-- 
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/0c3f0264-751d-486a-9079-bd512d7f6ee9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Would it be a good idea to build a IM app using django channels?

2017-03-31 Thread Andrew Godwin
Hi Vic,

Channels would be a suitable building block for such an app, certainly, but
you'd need to do a lot more work on top of it. Online presence management,
chat history, login, authentication, and the protocol would all be the
things you need to solve - Channels just gives you a basic eventing
framework and webhooks support to start building on (in the same way Django
doesn't come with, say, a built-in blog solution but the tools to build one
instead).

Consulting on how to build an entire app like this would be several days of
paid work for a good technical consultant, and they would be better placed
to work out the context and your requirements and recommend solutions, but
I would recommend using a relational database (PostgreSQL, MySQL) as a
primary message store, always. Channels would then use Redis as the
messaging transport; I wouldn't do caching initially as individual messages
is not a very cacheable problem (everyone's view is different).

Andrew

On Fri, Mar 31, 2017 at 4:05 PM, Vic Wei  wrote:

> I'm trying to build a django Instant Massage app, but I have some
> confusions,
> My app should the following needs:
> 1.be able to communicate in real time with browser, iOS, and Android
> native apps.
> 2.one user can send messages to another user in private
> 3.users can chat in serval chat room at a time
> 4.once a message is sent, it should be push to target user in realtime.
> 5.has a retry mechanism to guarantee delivery and messages should store in
> db like mysql
> Is django channels suite my requirements? Is there a limit amout of
> channel or is that what I need to do is create a group for each online user
> including ios and android ones?
> What my thought is using redis to cache the messages and store in MySQL,
> use celery to handle message store and distribute.
> Anyone could give some advices?
>
>
> --
> 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/228be88c-4ca8-4b52-875c-eb361e534e57%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/CAFwN1ur9iUyPmgE_XP8CTskEkg5waK%2BshHkLDguhR%3DqDxZupcg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Returning unique values from a foreign key in a ListView

2017-03-31 Thread Richard Jackson
Hi everyone,

*Goal*
- I have a ListView built around ModelA. 
- ModelA has a foreign key to ModelB. 
- I want to return a list with all unique entries of a required field (i.e. 
'foo') from ModelB.

*Context*
I have a table of clients (ModelA) and a table of jobs I do (ModelB), 
connected via foreign key - I want to retrieve a distinct list of all the 
jobs I do for the clients so I can render that into the template and make a 
user-facing filter.

*Problem 1*
Can't access values in ModelB using get_queryset()  as using this for 
ModelA and I don't know how to query multiple tables in such a statement:

views.py


from .models import ModelA
from django.views.generic import ListView, DetailView


# Create your views here.
class IndexView(ListView):
context_object_name = 'modela_list'
template_name = 'modela/index.html'


def get_queryset(self):
return ModelA.objects.order_by('title')


*Outcome 1*
Couldn't work out how to return the data from ModelA *AND* a unique list of 
'foo' values. Can return ALL values of 'foo' including duplicates (i.e. 
'Hello', 'Hello', 'World', 'World', 'Hello', rather than the desired 
'Hello', 'World')

*Problem 2*
Tried to do get_context_data though my understanding of this is very weak:

views.py



[code from Problem 1]
[...]
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
qs = context['modela_list']
list_of_values = qs.order_by().values('foo').distinct()
context.update(
{
'list_of_values': list_of_values,
}
)
return context


*Outcome 2*
Could return the unique values for the FOREIGN KEY values as they are in 
ModelA, could not return the assigned values from ModelB (i.e. '1', '2' 
returned, instead of 'Hello', 'World')

*Overall Outcome*
So I've managed to either get ALL the values of the required field from 
ModelB OR I can get the distinct values of the foreign key field from 
ModelA - but not the distinct values of the required field from ModelB!

Any help would be greatly appreciated!

Rich

-- 
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/10f50536-b5cc-4e30-8d28-a8ca1e0dce29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.