Inconsistency in form_class behavior, is this a Django ticket?
I'm wondering whether the following should be a Django ticket and would like your opinion on it. When I forget to set a value for 'template_name' using the TemplateMixin it returns a useful exception: "TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()'" Though when I forget to set the form_class while using the FormView, it returns the following unhelpful exception: "'NoneType' object is not callable" The behavior doesn't seem consistent to me and a more helpful message would have saved me some trouble. Is it worth creating a ticket for this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dc083c88-03f2-4ddf-b940-cda59d7f348b%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Remove old image file of ImageField
Hi, I've my django model with an ImageField. When I update (upload) a new image with the ImageField, the older image file remains in Media Folder. *How can I remove the old files when I update ImageField??* What is the best, clear, and simple approach to solve this problem? I've read a lot, but I've not found one real solution. Thanks! ... and sorry for my english! :) -- 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/ef4ca37f-9fc4-4cd3-bc98-0db58d922393%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Customize select widget in template
Hey people, *I need help customizing a "select" widget within the template.* I have a ModelForm and I am building a custom within the template. Looking at the documentation (https://docs.djangoproject.com/en/1.6/topics/forms/) I figured it out pretty quickly. One example: class="form-group"> > > class="control-label">{{ form.summary.label > }} > > type="text" >value="{{ form.summary.value|default_if_none:"" > }}" > > class="form-control"> > > The next thing really annoys me. There is no documentation on how to customize a select widget. It took me hours of trial and error to arrive at the point where I have all the necessary information to create this: > class="control-label">Fruit > > - > Apple > Pear > > > Now I am stuck at including the "selected" attribute, because somehow "choice.0" is not the same as "form.fruit.value" even though the output is the same. > {% for choice in form.fruit.field.choices %} > {{ choice.0 }} {{ form.fruit.value }} > {% if choice.0 == form.fruit.value %} > equals > {% endif %} > {% endfor %} > > Output: > 2 > 2 1 > 2 2 > *I know that I rather should create a custom Widget, but now that I started this way, I really like to know how to finish it this way.* -- 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/8f9cd469-6077-4382-95ee-b73b4036fdd3%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Django substitute old image of ImageFile
Hi, I've searched a lot for this problem, but I never found one real solution. I've a simple Django News model with an ImageField set correctly. *What I need is to delete the old image file when I upload a new image file with ImageField.* What is the best and clear solution? I've others model have others ImageField... with the same problem. One solution, maybe, is to clear Media Folder with an automated script... but... I prefer one standalone solution if is possible. ps: sorry for my english! :) -- 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/4f01e9d8-9718-443b-bf50-63646124b9ec%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Django test client encoding of JSON Booleans
On Friday, February 21, 2014 6:14:14 PM UTC-4:30, Daniel Smith wrote: > > I'm using Django version 1.5.5. Here is a short snippet of the test I'm > writing: > > from django.test import TestCase > > class MyTest(TestCase): > > def my_test(self): > url = ... location of my view ... > self.client.post(url, data={'active': False}, format='json') > > > The problem I'm running into is that when I inspect request.POST inside my > view, I get: {'active': [u'False']}. The workaround I have right now is to > use json.loads(request.raw_post_data), but I'm wondering if this is a bug > or if I am just missing something. Any help would be greatly appreciated. > Hello, The test client is not converting the data to json. 1. In your test module, you must convert the data to json and tell the correct content-type application/json: json_data = json.dumps({'active': False}) data = self.client.post(path=url, data=json_data, content_type='application/json') I notice that you use a format='json' parameter to post; I can't find anything about that parameter in the documentation or the code. You should use content_type='application/json' instead. 2. In the views module, you should parse the json data: if request.method == 'POST': body = request.body.decode('UTF-8') json_data = json.loads(body) print('views 12', json_data['active']) Kindly note that you should be using request.body instead of the deprecated raw_post_data. Regards, Camilo -- 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/61dc3c96-6572-479a-b4c0-7717e071aed9%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Inconsistency in form_class behavior, is this a Django ticket?
On Saturday, February 22, 2014 6:20:35 AM UTC-4:30, Jopr wrote: > > I'm wondering whether the following should be a Django ticket and would > like your opinion on it. > > When I forget to set a value for 'template_name' using the TemplateMixin > it returns a useful exception: > "TemplateResponseMixin requires either a definition of 'template_name' or > an implementation of 'get_template_names()'" > > Though when I forget to set the form_class while using the FormView, it > returns the following unhelpful exception: > "'NoneType' object is not callable" > > The behavior doesn't seem consistent to me and a more helpful message > would have saved me some trouble. Is it worth creating a ticket for this? > Hello, I think you can file a ticket on this, should be a quick fix candidate to be included in future releases. Please post here the ticket number after you do. Regards, Camilo. -- 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/17abc946-8f1a-4555-b22d-1e7353278488%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Django substitute old image of ImageFile
Any solutions?? :/ -- 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/3f3505eb-678c-41bd-be8b-63948a870488%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Django substitute old image of ImageFile
On 23/02/2014 9:51am, Fabrizio Alongi wrote: Any solutions?? :/ I'm interested too. I have it on my todo list to write a delete routine for my own software to get rid of uploaded files which are being replaced. I haven't decided whether to make it automatic or not. I haven't gotten around to it yet because other things have a higher priority. If I tackle it I'll post the fix here but if you do it before me I'd apreciate seeing how you do it. Cheers Mike -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/53093E3F.4090209%40dewhirst.com.au. For more options, visit https://groups.google.com/groups/opt_out.