Re: Best practice for passing JSON objects to a template

2015-04-24 Thread florent . pastor
I guess both methods are valid. 

Method one could be useful if it makes sense to have a data attribute.
Although, if it makes sense to have a data attribute filled up with JSON, and 
if the json is simple enough, then you can surely convert the json file to 
"data-" element (for exemple, {"name" : "yo", "city" : "lo"} becomes 'data-name 
= "yo" data-city = "lo"')
Also, if your concern is security (and also cleanliness of the code), you can 
also encode the JSON in base64 to avoid people reading too easily the data of 
the json file.

But methode 2 seem to make sense in most of the cases I can think of!
Plus it is far more simple ! :)

Cheers,
Florent

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f5a1bfa0-9774-4307-9f44-28a3413a92b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ListView CBV and a form

2015-04-24 Thread David
Hi

I am using the following:

class CreateComment(ListView):
model = Comment
paginate_by = 2
form_class = CommentForm

def post(self, request, *args, **kwargs):
if not request.user.is_authenticated():
return HttpResponseForbidden()

self.object = self.get_object()
self.object.creator = request.user
self.object.object_id = self.kwargs['pk']
self.object.content_type_id = self.kwargs['ct']
self.object.save()
return self.get(request, *args, **kwargs)

def get_queryset(self):
comments = Comment.objects.filter(
object_id=self.kwargs['pk'], content_type_id=self.kwargs['ct']
)
return comments

def get_context_data(self, **kwargs):
context = super(CreateComment, self).get_context_data(**kwargs)
context['form'] = CommentForm
return context

When I try this I get an error stating that there is no attribute 
'get_object'.

Is there a better way to process a form that is in a ListView?

Thank you for any assistance

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5e1b4630-351a-449e-a288-e8d136bc21ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Lone CR LF in email messages

2015-04-24 Thread Aron Podrigal
Hi,

I'm using django 1.6 with python3.2. I'm getting errors sending emails. Mail 
servers reject the emails due to lone CR or LF violating rfc2822. I searched 
with a hex editor where that is,  and i found it has a single \r at the end of 
the message. When I tried to debug outputting the message to a file before its 
sent and it had much more \r.  Had anyone else have such issue? Is it django or 
python libsmtp? 

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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/41ebfbb3-cb3c-4957-a143-8b51e26e1c15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ListView CBV and a form

2015-04-24 Thread David
This appears to work. Using a view for 2 functions seems pretty fugly 
though. Are there better ways to achieve this?

class CreateComment(ListView, FormMixin):
model = Comment
paginate_by = 2
form_class = CommentForm

def post(self, request, *args, **kwargs):
form = CommentForm(self.request.POST)
if form.is_valid():
obj = form.save(commit=False)
obj.creator = request.user
obj.object_id = self.kwargs['pk']
obj.content_type_id = self.kwargs['ct']
obj.save()
else:
return super(CreateComment, self).post(request, *args, **kwargs)

def get_queryset(self):
comments = Comment.objects.filter(
object_id=self.kwargs['pk'], content_type_id=self.kwargs['ct']
)
return comments

def get_context_data(self, **kwargs):
context = super(CreateComment, self).get_context_data(**kwargs)
context['form'] = CommentForm
return context

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dafda13d-6171-43ed-97b7-04c229e9dfbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


form_invalid redirection with CBVs

2015-04-24 Thread David
Following a form_invalid I need to redirect to the CreateComment view below 
with the errors shown in the form. Is this possible please? Highlighted is 
where I need help.

Thank you for any assistance.


class Comments(View):
def get(self, request, *args, **kwargs):
view = CreateComment.as_view()
return view(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
view = CommentCreate.as_view()
return view(request, *args, **kwargs)

class CreateComment(ListView):
model = Comment
paginate_by = 2

def get_queryset(self):
comments = Comment.objects.filter(
object_id=self.kwargs['pk'], content_type_id=self.kwargs['ct']
).order_by('-created')
return comments

def get_context_data(self, **kwargs):
context = super(CreateComment, self).get_context_data(**kwargs)
context['form'] = CommentForm()
return context

class CommentCreate(SingleObjectMixin, FormView):
template_name = 'comment/comment_list.html'
form_class = CommentForm
model = Comment

def post(self, request, *args, **kwargs):
self.object = self.get_object()
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form)

def get_success_url(self):
return reverse('comment:Comments', kwargs={'ct': self.kwargs['ct'], 'pk': 
self.kwargs['pk']})

def form_valid(self, form):
data = form.save(commit=False)
data.creator = self.request.user
data.object_id = self.kwargs['pk']
data.content_type_id = self.kwargs['ct']
data.save()
return super(CommentCreate, self).form_valid(form)

def form_invalid(self, form):
*return super (CommentCreate, self).form_invalid(form)*

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/74848a77-5af5-4947-a541-f3812a285d99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ListView CBV and a form

2015-04-24 Thread felix

El 24/04/15 06:08, David escribió:
This appears to work. Using a view for 2 functions seems pretty fugly 
though. Are there better ways to achieve this?


class CreateComment(ListView, FormMixin):
model = Comment
paginate_by = 2
form_class = CommentForm

def post(self, request, *args, **kwargs):
form = CommentForm(self.request.POST)
if form.is_valid():
obj = form.save(commit=False)
obj.creator = request.user
obj.object_id = self.kwargs['pk']
obj.content_type_id = self.kwargs['ct']
obj.save()
else:
return super(CreateComment, self).post(request, *args, **kwargs)

def get_queryset(self):
comments = Comment.objects.filter(
object_id=self.kwargs['pk'], content_type_id=self.kwargs['ct']
)
return comments

def get_context_data(self, **kwargs):
context = super(CreateComment, self).get_context_data(**kwargs)
context['form'] = CommentForm
return context

I think that you shoul use CreateView to create new objects or 
UpdateView to update them.

ListView is used to represent a list of objects.

Cheers,
Felix.

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/553A33D6.3070407%40epepm.cupet.cu.
For more options, visit https://groups.google.com/d/optout.


Database and migrations are out of sync.

2015-04-24 Thread Андрей Лукьянов
Hi everyone. In my current project there is a great confusion of migrations 
and it often ends up in an error when I try to apply migrations because the 
fields the migrate tries to create are already in the database. Is there 
any way for migrate to create fields that are not in the database and skip 
those that are already there? Sort of a partial migration. Now I have to 
edit migration files manually commenting the fields that are already in the 
database. Takes a lot of time for I can't compare the database state and 
the state of migrations. So I have to do it field by field...

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9e80a555-2b84-4a53-a4eb-2096f3e4acca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: form_invalid redirection with CBVs

2015-04-24 Thread David
This is what I am working from 
btw: 
https://docs.djangoproject.com/en/1.8/topics/class-based-views/mixins/#an-alternative-better-solution

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8679e420-18e0-43be-90f6-092be5558cf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best practice for passing JSON objects to a template

2015-04-24 Thread Piper Merriam
Look at django-argonauts

https://github.com/fusionbox/django-argonauts

It provides a nice (safe) template tag you can use to filter json 
serializable python objects into safe javascript objects.

On Thursday, April 9, 2015 at 11:50:50 AM UTC-6, Eric Plumb wrote:
>
> Hi Djangoers!
>
> Sometimes in the course of human events it becomes necessary to encode a 
> JSON object directly into a template.  We all prefer AJAX and REST APIs and 
> the rest of the TOFLAs, but in the cases where it has to be part of the 
> template, I'm wondering if there's an accepted canonical best-practice way 
> to do so and remain safe from XSS attacks and other nastiness.
>
> I'm aware of the following two methods:
>
> 1. HTML attribute loaded by jQuery's $.data()
>
> # view
> return { ... {'my_obj': mark_safe(escape(json.dumps(obj))) } ... }
>
> # template
> ...
>
> # JS
> var myObj = $('div').data('my-object');  // implicitly calls JSON.parse() 
> on the encoded object
>
> 2. Explicitly parsed JS object
>
> # view
> return { ... {'my_obj': mark_safe(escapejs(json.dumps(obj))) } ... }
>
> # template
> 
>   var myObj = JSON.parse('{{ my_obj }}')
> 
>
> Are there better methods?  It seems like this ought to come up often in 
> building safe websites, but I don't see a consensus out there on the Web. 
>  Thanks in advance for your consideration!
>
> Eric
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7e3f929f-c2c2-405d-bd76-327939f2ce78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Database and migrations are out of sync.

2015-04-24 Thread Tim Graham
I don't think so. When you create your initial migrations, you need to 
ensure they match the scheme of your database. After that, things shouldn't 
get out of sync. Any idea how that happened in the first place?

On Friday, April 24, 2015 at 8:54:19 AM UTC-4, Андрей Лукьянов wrote:
>
> Hi everyone. In my current project there is a great confusion of 
> migrations and it often ends up in an error when I try to apply migrations 
> because the fields the migrate tries to create are already in the database. 
> Is there any way for migrate to create fields that are not in the database 
> and skip those that are already there? Sort of a partial migration. Now I 
> have to edit migration files manually commenting the fields that are 
> already in the database. Takes a lot of time for I can't compare the 
> database state and the state of migrations. So I have to do it field by 
> field...
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/57f91160-b623-418d-a82e-a80fd672d977%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: annotate() questions

2015-04-24 Thread Carsten Fuchs

Am 17.04.2015 um 21:14 schrieb Carsten Fuchs:

Now if only I knew how to obtain the actual book objects related to the min/max 
prices...


Just for future reference, the best answer that I've found so far is:
http://blog.roseman.org.uk/2010/08/14/getting-related-item-aggregate/

Best regards,
Carsten

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/553A7189.1010804%40cafu.de.
For more options, visit https://groups.google.com/d/optout.


Django restframework based app on heroku showing error HTTP/1.1 505 HTTP Version Not Supported

2015-04-24 Thread Anand Singh


I need to send some data from an arduino to an rest based web application.

To test I have created an django based web application on heroku 
http://obttracker.herokuapp.com/api/

Now when I trying to send the data from arduino using GSM AT commands it's 
showing below error

HTTP/1.1 505 HTTP Version Not Supported Connection: close Server: Cowboy

Below is my code in arduino

  const char HTTP_HEADER_POST[ ] = "POST /api/sprints  HTTP/1.1\r\nHost: 
obttracker.herokuapp.com\r\nContent-Length: 54\r\n\r\nUser-Agent: 
obttracker\r\nConnection: keep-alive\r\nContent-Type: 
application/x--form-urlencoded\r\nAuthorization: Basic 
ZGVtbzpkZW1v\r\n\r\n";  //HTTP header line before length 
  const char HTTP_BODY_POST[] = 
"end=2015-05-19&name=TESTING&point=POINT%2834.2+45.3%29";

   int tmp_post_len = strlen(HTTP_HEADER_POST);  
   //sending header packet to remote host
   gsm_port.print("AT+QISEND=");
   gsm_port.print(tmp_post_len); 
   gsm_port.print("\r");

   delay(500);
   gsm_get_reply();

   //sending header 
   gsm_port.print(HTTP_HEADER_POST);

   delay(500);
   gsm_get_reply();

   //validate header delivery
   gsm_validate_tcp();

   // send the body data
   int body_len = strlen(HTTP_BODY_POST);
   gsm_port.print("AT+QISEND=");
   gsm_port.print(body_len); 
   gsm_port.print("\r");

   delay(500);
   gsm_get_reply();  

   gsm_port.print(HTTP_BODY_POST);

   delay(500);
   gsm_get_reply(); 

   //validate previous transmission  
   gsm_validate_tcp();

   parse_receive_reply();

I have tested the web app by send through my linux system using python 
requests, and it's working below are the details

   $ python
   Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
   [GCC 4.7.2] on linux2
   Type "help", "copyright", "credits" or "license" for more information.
   >>> import datetime
   >>> import requests
   >>> import pprint
   >>> today = datetime.date.today()
   >>> data = {'name': 'TESTSTING', 'end': today, 'point': 'POINT(56.3
33.3)'}
   >>> resp = requests.get('http://obttracker.herokuapp.com/api')
   >>> resp.status_code
   200
   >>> api = resp.json()
   >>> pprint.pprint(api)
   {u'sprints': u'http://obttracker.herokuapp.com/api/sprints'}
   >>> resp = requests.post(api['sprints'], data=data, auth=('demo', 'demo'))
   >>> resp.status_code
   201
   >>> sprint = resp.json()
   >>> pprint.pprint(sprint)
   {u'end': u'2015-04-24',
u'id': 3,
u'links': {u'self': u'http://obttracker.herokuapp.com/api/sprints/3'},
u'name': u'TESTSTING',
u'point': {u'coordinates': [56.3, 33.3], u'type': u'Point'}}
   >>> 

Request to please provide me suggestion or help to resolve this issue

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4dcc9750-9f45-4bef-9563-169c711f699f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django 1.8.1 : A server error occurred. Please contact the administrator.

2015-04-24 Thread JMKoushyar
Ho guys, I'm new to django framework. According to Instructions in the 
djangoproject.com I did all the things and everything was pretty good but 
when I tried to open my django project in browser by "python manage.py 
runserver", I got some errors. The page error is : A server error occurred. 
Please contact the administrator.

Also Here Is the command prompt errors given :

"""C:\Users\Javad\Desktop\havij>python manage.py runserver Performing 
system checks... System check identified no issues (0 silenced). April 24, 
2015 - 21:34:56 Django version 1.8, using settings 'havij.settings' 
Starting development server at http://127.0.0.1:8000/ Quit the server with 
CTRL-BREAK. Traceback (most recent call last): File 
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 21, in 
import_string module_path, class_name = dotted_path.rsplit('.', 1) 
ValueError: need more than 1 value to unpack During handling of the above 
exception, another exception occurred: Traceback (most recent call last): 
File "C:\Python34\lib\wsgiref\handlers.py", line 137, in run self.result = 
application(self.environ, self.start_response) File 
"C:\Python34\lib\site-packages\django\contrib\staticfiles\handlers.py", l 
ine 63, in __call__ return self.application(environ, start_response) File 
"C:\Python34\lib\site-packages\django\core\handlers\wsgi.py", line 170, i n 
__call__ self.load_middleware() File 
"C:\Python34\lib\site-packages\django\core\handlers\base.py", line 50, in 
load_middleware mw_class = import_string(middleware_path) File 
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 24, in 
import_string six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) 
File "C:\Python34\lib\site-packages\django\utils\six.py", line 658, in 
reraise raise value.with_traceback(tb) File 
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 21, in 
import_string module_path, class_name = dotted_path.rsplit('.', 1) 
ImportError: polls doesn't look like a module path [24/Apr/2015 
21:35:04]"GET / HTTP/1.1" 500 59 Traceback (most recent call last): File 
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 21, in 
import_string module_path, class_name = dotted_path.rsplit('.', 1) 
ValueError: need more than 1 value to unpack During handling of the above 
exception, another exception occurred: Traceback (most recent call last): 
File "C:\Python34\lib\wsgiref\handlers.py", line 137, in run self.result = 
application(self.environ, self.start_response) File 
"C:\Python34\lib\site-packages\django\contrib\staticfiles\handlers.py", l 
ine 63, in __call__ return self.application(environ, start_response) File 
"C:\Python34\lib\site-packages\django\core\handlers\wsgi.py", line 170, i n 
__call__ self.load_middleware() File 
"C:\Python34\lib\site-packages\django\core\handlers\base.py", line 50, in 
load_middleware mw_class = import_string(middleware_path) File 
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 24, in 
import_string six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) 
File "C:\Python34\lib\site-packages\django\utils\six.py", line 658, in 
reraise raise value.with_traceback(tb) File 
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 21, in 
import_string module_path, class_name = dotted_path.rsplit('.', 1) 
ImportError: polls doesn't look like a module path [24/Apr/2015 
21:35:06]"GET / HTTP/1.1" 500 59"""

Please help me :|, I really need your help guys. 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d14d2fde-f022-4234-b4f7-9decc0748a1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Slowness of the resulting squashed migration

2015-04-24 Thread aRkadeFR

Hello,

After working on a project and having around 10 migrations per app,
I wanted to refactor some migrations (of the same app) into only one
and have a faster migrations while testing.

I did squashmigrations on many of the migrations, but the resulting
squased migration is still pretty slow (around 6 seconds to create 4
tables on MySQL 5.5 without any data inserted).

After looking at the migrations, there is some CreateModel(name='')
and after the table creation some AddField on the same table/models...

I would like to know if it's safe to change the migrations by hand? Is
there a reason the squashmigrations didn't refactor into only CreateModel
without AddField then?

Thanks

aRkadeFR

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/553A87EB.9080506%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Re: Database and migrations are out of sync.

2015-04-24 Thread felix

El 24/04/15 12:16, Tim Graham escribió:
I don't think so. When you create your initial migrations, you need to 
ensure they match the scheme of your database. After that, things 
shouldn't get out of sync. Any idea how that happened in the first place?


On Friday, April 24, 2015 at 8:54:19 AM UTC-4, Андрей Лукьянов wrote:

Hi everyone. In my current project there is a great confusion of
migrations and it often ends up in an error when I try to apply
migrations because the fields the migrate tries to create are
already in the database. Is there any way for migrate to create
fields that are not in the database and skip those that are
already there? Sort of a partial migration. Now I have to edit
migration files manually commenting the fields that are already in
the database. Takes a lot of time for I can't compare the database
state and the state of migrations. So I have to do it field by
field...


it happens if you work on different copies of your project and delete 
some migration files. That's what happened to 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/553A88EA.2020202%40epepm.cupet.cu.
For more options, visit https://groups.google.com/d/optout.


Re: Slowness of the resulting squashed migration

2015-04-24 Thread Markus Holtermann
Hi,

In principle it is possible to write your own or modify existing migrations 
unless they are already applied.

Regarding the additional AddField() operations: in case you have e.g. 
circular references between two models Django cannot add both models with 
their full columns at the same time. Django first adds one model without 
the ForeignKey, then the second model including the FK to the first model 
and finally adds the field to the first model pointing to the second model 
[1]. Bottom line: if you find a way to optimize something in your squashed 
migration, feel free to go ahead. It would be helpful if you report this as 
an enhance to our issue tracker [2] so we can include a possible 
improvement in future Django versions.

/Markus

[1] Have a look at slide 14f 
of https://speakerdeck.com/andrewgodwin/migrations-under-the-hood
[2] https://code.djangoproject.com/

On Friday, April 24, 2015 at 8:14:34 PM UTC+2, aRkadeFR wrote:
>
> Hello, 
>
> After working on a project and having around 10 migrations per app, 
> I wanted to refactor some migrations (of the same app) into only one 
> and have a faster migrations while testing. 
>
> I did squashmigrations on many of the migrations, but the resulting 
> squased migration is still pretty slow (around 6 seconds to create 4 
> tables on MySQL 5.5 without any data inserted). 
>
> After looking at the migrations, there is some CreateModel(name='') 
> and after the table creation some AddField on the same table/models... 
>
> I would like to know if it's safe to change the migrations by hand? Is 
> there a reason the squashmigrations didn't refactor into only CreateModel 
> without AddField then? 
>
> Thanks 
>
> aRkadeFR 
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c75633dd-b41a-46af-9e72-ced31e2e6885%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ModelForm not creating field with required options

2015-04-24 Thread victor menezes
Hi all,

I'm using Django 1.8 and having trouble to because my form does not 
generate fields with required option even though they have the property 
"blank=False" in the model.
In the example bellow, shouldn't the field "description" have the 
"required" attribute in the html generated using "form.as_p" or am I 
missing anything?

*models.py*
class Place(models.Model):
name = models.CharField(max_length=200, blank=False, default='')
owners = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=False)
members = models.ManyToManyField(Member, blank=True)
*description =  models.TextField(blank=False)*
location = models.CharField(max_length=400, blank=True)
additional_info = models.TextField(blank=True)

def __unicode__(self):
return self.name


class PlaceForm(ModelForm):
class Meta:
model = Place
fields = '__all__'

*views.py*
@login_required(login_url='/')
def addPlaceView(request):
place_form = PlaceForm()
context = {
'form': place_form,
}
return render(request, 'newPlace.html', context)

*newPlace.html*

{% csrf_token %}
{{ form.as_p }}



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/84a2cdf8-f6de-438b-b7d3-775c4300f105%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django 1.8.1 : A server error occurred. Please contact the administrator.

2015-04-24 Thread Mike Dewhirst

On 25/04/2015 3:13 AM, JMKoushyar wrote:

Ho guys, I'm new to django framework. According to Instructions in the
djangoproject.com I did all the things and everything was pretty good
but when I tried to open my django project in browser by "python
manage.py runserver", I got some errors. The page error is : A server
error occurred. Please contact the administrator.


It would be helpful to see the code which generates the error. But 
anyway, I think it is identified in your stack trace here ...


class_name = dotted_path.rsplit('.', 1)
ImportError: polls doesn't look like a module path

... where you import polls, are you using a backslash anywhere? The 
framework is expecting a dot instead of a slash or (in your case) backslash.


For example, you might be using "from myproject\polls import something" 
and that should instead be "from myproject.polls import something"


What makes this work is the existence of a (probably empty) file called 
__init__.py in each directory on either side of the path separator 
(unix/linux/mac slash or windows backslash) so you might also check you 
have those __init__.py files in place.


hth

Mike





Also Here Is the command prompt errors given :

"""C:\Users\Javad\Desktop\havij>python manage.py runserver Performing
system checks... System check identified no issues (0 silenced). April
24, 2015 - 21:34:56 Django version 1.8, using settings 'havij.settings'
Starting development server at http://127.0.0.1:8000/ Quit the server
with CTRL-BREAK. Traceback (most recent call last): File
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 21,
in import_string module_path, class_name = dotted_path.rsplit('.', 1)
ValueError: need more than 1 value to unpack During handling of the
above exception, another exception occurred: Traceback (most recent call
last): File "C:\Python34\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response) File
"C:\Python34\lib\site-packages\django\contrib\staticfiles\handlers.py",
l ine 63, in __call__ return self.application(environ, start_response)
File "C:\Python34\lib\site-packages\django\core\handlers\wsgi.py", line
170, i n __call__ self.load_middleware() File
"C:\Python34\lib\site-packages\django\core\handlers\base.py", line 50,
in load_middleware mw_class = import_string(middleware_path) File
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 24,
in import_string six.reraise(ImportError, ImportError(msg),
sys.exc_info()[2]) File
"C:\Python34\lib\site-packages\django\utils\six.py", line 658, in
reraise raise value.with_traceback(tb) File
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 21,
in import_string module_path, class_name = dotted_path.rsplit('.', 1)
ImportError: polls doesn't look like a module path [24/Apr/2015
21:35:04]"GET / HTTP/1.1" 500 59 Traceback (most recent call last): File
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 21,
in import_string module_path, class_name = dotted_path.rsplit('.', 1)
ValueError: need more than 1 value to unpack During handling of the
above exception, another exception occurred: Traceback (most recent call
last): File "C:\Python34\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response) File
"C:\Python34\lib\site-packages\django\contrib\staticfiles\handlers.py",
l ine 63, in __call__ return self.application(environ, start_response)
File "C:\Python34\lib\site-packages\django\core\handlers\wsgi.py", line
170, i n __call__ self.load_middleware() File
"C:\Python34\lib\site-packages\django\core\handlers\base.py", line 50,
in load_middleware mw_class = import_string(middleware_path) File
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 24,
in import_string six.reraise(ImportError, ImportError(msg),
sys.exc_info()[2]) File
"C:\Python34\lib\site-packages\django\utils\six.py", line 658, in
reraise raise value.with_traceback(tb) File
"C:\Python34\lib\site-packages\django\utils\module_loading.py", line 21,
in import_string module_path, class_name = dotted_path.rsplit('.', 1)
ImportError: polls doesn't look like a module path [24/Apr/2015
21:35:06]"GET / HTTP/1.1" 500 59"""

Please help me :|, I really need your help guys.

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/d14d2fde-f022-4234-b4f7-9decc0748a1f%40googlegroups.com


Re: static files and DEBUG = False

2015-04-24 Thread Florian Schweikert
On 21/04/15 23:49, egon.frer...@gmx.de wrote:
> settings.py contains ALLOWED_HOSTS with the host in the form
> ".example.com". With DEBUG = True I get the complete page. But if I set
> DEBUG = False the static files are not found so I get only the content.

Django does not serve static files if DEBUG=False, and you really don't
want to do that.

> If DEBUG = True  the apache access log the static files are shown with
> HTTP-code 200. If DEBUG = False Apache is looking for the static files
> two times. The first try gives  status code 301, the second try gives 
> status code 500.
> 
> Any idea why this happens?

It's a bad idea to serve statics with Django.
It's ok for debugging, but not for production.
If you already use apache serve static files with Apache directly.

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/553B3300.8040108%40ist-total.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature