data not validating after image field added to model form
I just added am image field to a model form but when I try to upload an image using the form, it gives me the following error saying that the data could not be validated. I don't understand though, what is it about the image that could not be validated? Is there any way to decipher this from this error? Environment: Request Method: POST Request URL: http://127.0.0.1:8000/registration/ Django Version: 1.3 Python Version: 2.6.6 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin', 'mysite.books', 'mysite.registration'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "C:\Users\Shazeb\django_code\mysite\..\mysite\registration \views.py" in register 23. reg.save() File "C:\Python26\lib\site-packages\django\forms\models.py" in save 363. fail_message, commit, construct=False) File "C:\Python26\lib\site-packages\django\forms\models.py" in save_instance 73. " validate." % (opts.object_name, fail_message)) Exception Type: ValueError at /registration/ Exception Value: The Company could not be created because the data didn't validate. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: data not validating after image field added to model form
On Sun, Jul 17, 2011 at 01:19:59AM -0700, sq1020 wrote: > I just added am image field to a model form but when I try to upload > an image using the form, it gives me the following error saying that > the data could not be validated. I don't understand though, what is > it about the image that could not be validated? Is there any way to > decipher this from this error? As the traceback suggests, the form didn't validate. That means you have to inspect its errors to see the specific reasons. By the way, usually you want to wrap the form.save call in try ... except to catch this exact exception and redisplay the form to the user in case it doesn't validate. Michal signature.asc Description: Digital signature
Django admin: naming subclass objects, fieldsets and displaying items from other class.
Hi 1. When in django.admin I want to pick a source from dropdown list it always lists every item as "source object". How I can modify it so it will show source_name from Source model? from django.contrib import admin from news.models import News, Comment, Source class NewsAdmin(admin.ModelAdmin): date_hierarchy = 'date_added' list_display = ('date_added', 'title', 'created_by') list_display_links = ('date_added', 'title', 'created_by', ) fields = ['title', 'text', "source", 'created_by'] class SourceAdmin(admin.ModelAdmin): list_display = ('source_name', 'source_url') Models: class News(models.Model): source = models.ForeignKey("Source", related_name="source_name_set", blank=True, null=True) class Source(models.Model): source_name = models.CharField(max_length=50) source_url = models.URLField("Link") 2. I am having a problem with fieldsets in django admin, second parameter "advanced options does not work for any subclass of models. It always returns me an error: 'NewsAdmin.fieldsets[1][1]['fields']' refers to field 't' that is missing from the form. where field "x" is always the first letter of particural model subclass for exmaple "s" - source, "t" title. fieldsets = ( (None, { 'fields': ('text') }), ('Advanced options', { 'classes': ('collapse',), 'fields': ('title') }), ) 3. In list display in admin.model I'd like to view connected data (foreign key) from another model. For example I have a CommentAdmin class and I want to see the title from NewsAdmin class and link it to particural news. I have completely no idea how to do it - I couldn't find any examples in django docs class CommentAdmin(admin.ModelAdmin): date_hierarchy = 'date_added' list_display = ('id', 'date_added', 'title', ) class NewsAdmin(admin.ModelAdmin): date_hierarchy = 'date_added' list_display = ('date_added', 'title', 'created_by') list_display_links = ('date_added', 'title', 'created_by', ) fields = ['title', 'text', "source", 'created_by'] Please provide me some hints and help with these 3 issues and I will try to resolve the problems :) I will appreciate it -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/xUCspWwaOmIJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django admin: naming subclass objects, fieldsets and displaying items from other class.
1. Define a unicode method on Source that returns whatever you want to display. 2. Missing comma in one-element tuple. mjl -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Z9XM3xXdbVsJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django admin: naming subclass objects, fieldsets and displaying items from other class.
Both helped. 3rd problem to go ;) -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/1F7cf6lXgjMJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django admin: naming subclass objects, fieldsets and displaying items from other class.
On Sunday, 17 July 2011 10:49:37 UTC+1, Petey wrote: > > Both helped. > > 3rd problem to go ;) > https://docs.djangoproject.com/en/1.3/ref/contrib/admin/ - see the third bullet point. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/OPnXGiUkPLsJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
trouble going from django on Windows to Ubuntu using Eclipse & Aptana Studio
Hi I'm pretty new to Django but I had an app working OK so far in WIdnows in Eclipse with the Aptana Studio plugin. I installed Eclipse and Aptana on a Ubuntu 11 machine and copied the code into a new project and when I try to run the (development) server I get some errors in django itself that are incomprehensible to me: Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C. utility.execute() File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/ django/core/management/__init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/ django/core/management/base.py", line 191, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/ django/core/management/base.py", line 220, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/ django/core/management/commands/runserver.py", line 67, in handle self.run(*args, **options) File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/ django/core/management/commands/runserver.py", line 76, in run autoreload.main(self.inner_run, args, options) File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/ django/utils/autoreload.py", line 131, in main reloader(main_func, args, kwargs) File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/ django/utils/autoreload.py", line 104, in python_reloader reloader_thread() File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/ django/utils/autoreload.py", line 83, in reloader_thread ensure_echo_on() File "/usr/local/lib/python2.7/dist-packages/Django-1.3-py2.7.egg/ django/utils/autoreload.py", line 77, in ensure_echo_on attr_list = termios.tcgetattr(fd) termios.error: (22, 'Invalid argument') Finished "/home/dug/workspace/snyder_link/src/snyder_link/manage.py runserver" execution. Could someone explain where the problems might be? Even a beginning of a solution would be appreciated as I don't know where to begin Best Doug -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: trouble going from django on Windows to Ubuntu using Eclipse & Aptana Studio
Well, i would recommend that you use a simple editor(like vim in linux) or Programmer's Notepad(in windows) for development in django/python. It is much easier to develop and also helps you keep your development environment 'lightweight'. An IDE is required only for languages like Java, where there is loads of boilerplate code; python inherently doesnt have much of it, and hence the rationale to switch over to a 'simple editor'. -V -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
.exclude method generating incorrect sql?
I have a query where it looks like Django 1.3 is generating incorrect sql. It involves these four models. class Aaa(models.Model): pass class Bbb(models.Model): aaa = models.ForeignKey(Aaa, related_name='bbbs') class Ccc(models.Model): bbb = models.ForeignKey(Bbb, related_name='cccs') class Ddd(models.Model): aaa = models.ForeignKey(Aaa, related_name='ddds') passed = models.BooleanField() So here's the query; I expect it to give me the number of cccs that are not attached to a non-passed ddd. I [1]: Ccc.objects.exclude(bbb__aaa__ddds__passed=False).count() Here's the sql generated by django, from connection.queries: SELECT COUNT(*) FROM "myapp_ccc" INNER JOIN "myapp_bbb" ON ("myapp_ccc"."bbb_id" = "myapp_bbb"."id") WHERE NOT (("myapp_bbb"."aaa_id" IN (SELECT U1."id" FROM "myapp_bbb" U1 INNER JOIN "myapp_aaa" U2 ON (U1."aaa_id" = U2."id") INNER JOIN "myapp_ddd" U3 ON (U2."id" = U3."aaa_id") WHERE U3."passed" = false ) AND "myapp_bbb"."aaa_id" IS NOT NULL)) It looks like the inner select statement returns a list of bbb ID's, but the WHERE NOT condition asks if a aaa id is in the list of bbb ID's, which doesn't make any sense. Basically, it should say: WHERE NOT (("myapp_bbb"."id" IN (SELECT U1."id" What do you think? Is this a bug? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Multiple Databases || External Databases
I am building a Django User profile management portal. In one of the sections of the website i need pull data from an external database(Its managed by someone else, i have access to it). How can i achieve this and also can someone please point me to a working example. Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django - can't open image in model save()
def upload_path_handler(instance, filename): return filename class SpectacleGallery(models.Model): image = models.ImageField(upload_to=upload_path_handler) def save(self, *args, **kwargs): Image.open(self.image) super(SpectacleGallery, self).save(*args, **kwargs) When I try to open it I get: IOError at /admin/index/spectacle/1/ cannot identify image file Why? File is a proper image. Does that file in save methos is not a good format for PIL? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/h3NJ7_3vezwJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.