testing a model that uses stored procedures
Hello, I have a model that uses a stored procedure + a column outside of django's control for specialized selects. My problem is that I don't see a good way of testing my related python code for that model. Since I need to execute some SQL code at the beginning of each test, right after the fixtures are applied, I can always get a db cursor, and execute it in the setUp method. However, that would make the whole test a bit more unreadable, and harder to maintain. What I want is to give the test an sql file, much like a fixture is given. Is there something like this? -- 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.
Explicitly telling django that the reverse OneToOne relationship doesn't exist
Hello, I have a database function that returns the necessary data for constructing a bunch of related objects in one go. One of the objects has a OneToOne relationship with my main model instance, and it doesn't exists for every object of the main model. Since the main model has a reverse relationship with that class, I am looking for a good way to emulate the select_related behaviour for it. My problem is that, even if I set the relationships in the instances that have it, the rest will not be set, and Django will hit the database, trying to figure out if such relationships exist (I already know they don't). So I am looking for the method which 'select_related' uses to tell Django that certain objects don't have reverse relationships. -- 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.
Handling readonly fields in the admin, which are provided by the form
Hello, I'm having a bit of a problem providing a custom readonly field, which is defined in the form. The field is defined in the form, as such: class Form(forms.modelForm): field = myCustomField() The field is also associated with a custom widget, which is set in the form's __init__. it is included in a fieldset with its name - 'field', and under normal circumstances is writable. This works just fine. However, if I add this field to the self.readonly_fields list in the modelAdmin's change_view, django complains that it cannot find it anymore. After a lot of debugging, I worked around that by defining a method in the modelAdmin: def fields(self, instance): form = self.form(instance=instance) widget = form.fields['field'].widget widget.is_readonly = True value = instance.some_field return widget.render('field', value) field.short_description = _('Lookup') field.allow_tags = True While this works, I don't feel it is the correct approach. I didn't even find any documentation on it, and I have to instantiate the form again, just to get the field's widget, plus I also have to construct the value again. Is there a better way to achieve this? How can I get that the field is read-only from the widget itself? -- 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.
Inlining a reverse foreign key relationship in django admin
Hi, Consider the following models: class Foo(models.Model): name = models.CharField(max_length=100) class Bar(models.Model): name = models.CharField(max_length=100) city = models.ForeignKey(Foo) How can I inline the admin model form for Foo into Bar, so that I can add new Foo items if needed? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Getting model instances from cursor fetches
Hello, I have a stored procedure which creates a cursor for a query, and also returns the total count for the (unlimited) query. The query itself can be mapped to my model if ran through the raw method of the manager. However, I'm interested in using the procedure, rather than 2 separate queries for the count and the instances. The documentation indicates that I should use the connection.cursor method for invoking custom sql. My initial plan is to first execute the procedure, which would return the count and open the query cursor, and then execute a 'fetch all' for that cursor (I doubt 'fetch next' would be better, since the result is stuffed into the django cursor anyway, but I could be wrong here). But after I fetch from the query cursor, how do I initialize my model objects with the data from that cursor? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
can't pickle Input objects -- error in django 1.3 beta 1 with memcached cache backend
Hi, With django 1.3 alpha 1, I was using the following piece of code in my urls.py without a problem: cache_page(views.IndexView.as_view(), timeout) When upgrading to 1.3 beta 1, I got this error: Environment: Request Method: GET Request URL: http://localhost:8000/bg/ Django Version: 1.3 beta 1 Python Version: 2.6.6 Installed Applications: ['localeurl', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', 'registration', 'main'] Installed Middleware: ('localeurl.middleware.LocaleURLMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware') Traceback: File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/ base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python2.6/dist-packages/django/utils/ decorators.py" in _wrapped_view 101. result = middleware.process_response(request, response) File "/usr/local/lib/python2.6/dist-packages/django/middleware/ cache.py" in process_response 89. self.cache.set(cache_key, response, timeout) File "/usr/local/lib/python2.6/dist-packages/django/core/cache/ backends/memcached.py" in set 64. self._cache.set(key, value, self._get_memcache_timeout(timeout)) File "/usr/local/lib/python2.6/dist-packages/memcache.py" in set 525. return self._set("set", key, val, time, min_compress_len) File "/usr/local/lib/python2.6/dist-packages/memcache.py" in _set 739. store_info = self._val_to_store_info(val, min_compress_len) File "/usr/local/lib/python2.6/dist-packages/memcache.py" in _val_to_store_info 711. pickler.dump(val) File "/usr/lib/python2.6/copy_reg.py" in _reduce_ex 70. raise TypeError, "can't pickle %s objects" % base.__name__ Exception Type: TypeError at / Exception Value: can't pickle Input objects With the val in question being this: Can someone guide me into fixing the invocation, or should I file a bug against beta 1? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.