PRG with View classes
hi, Is there out of the box support for the PRG pattern with Django's new class-based views? If not, what's a good/preferred way of implementing one? Thanks D. -- 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/-/6D8VtiHVO-wJ. 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: anti-join query in Django
Hi Russ, Thanks for a quick response. I don't think Django needs to make the decision of whether or not to do a join. That can be done by the underlying database as long as Django generates a query that the database can understand and optimize properly. In this case, it would imply that Django would still need to generate a join, but check the null condition not on the primary key field but on one of the fields the join condition. Regardless, I'm going to file a ticket on this. Thanks again. D. On Nov 19, 2:36 am, Russell Keith-Magee <russ...@keith-magee.com> wrote: > On Sat, Nov 19, 2011 at 8:41 AM, dmitry b <dmitry.ma...@gmail.com> wrote: > > Is there a recommended approach to anti-join queries? Here's the > > query I'm having an issue with: > > > Branch.objects.filter(branchgroup__isnull=True)[:1] > > > where branchgroup is a ManytoMany relationship to another model. I > > want to get a set of Branch objects that aren't mapped to any > > BranchGroups. > > Hi Dmitry, > > There isn't any specific way to force the non-creation of a join > condition; Django doesn't expose the internals of query construction, > and should be choosing the optimal SQL for the ORM query. > > The sort of optimization you describe (i.e., don't do the join if you > can just check the primary key value on the local model) is an > optimization that Django is definitely capable of performing. If the > ORM isn't performing this optimization in this case, it's possible > you've found a bug. > > There are some cases where the optimization *isn't* possible, but > without seeing the models for your test case, it's impossible to say > for certain. > > If you think you've found a way that Django could optimize it's > queries better, the best way forward is to open a ticket, with a set > of sample models and the expected/actual query that is generated for > those specific models. > > Yours, > Russ Magee %-) -- 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.
anti-join query in Django
Is there a recommended approach to anti-join queries? Here's the query I'm having an issue with: Branch.objects.filter(branchgroup__isnull=True)[:1] where branchgroup is a ManytoMany relationship to another model. I want to get a set of Branch objects that aren't mapped to any BranchGroups. This query gets translated to the following (a simplified equivalent): SELECT "scm_branch"."id" FROM "scm_branch" LEFT OUTER JOIN "scm_branchgroup_branches" ON ("scm_branch"."id" = "scm_branchgroup_branches"."branch_id") LEFT OUTER JOIN "scm_branchgroup" ON ("scm_branchgroup_branches"."branchgroup_id" = "scm_branchgroup"."id") WHERE "scm_branchgroup"."id" IS NULL LIMIT 1 This query is very slow: Limit (cost=1072479.36..6256437.79 rows=1 width=145) However, a slightly modified, but functionally equivalent query: SELECT "scm_branch"."id" FROM "scm_branch" LEFT OUTER JOIN "scm_branchgroup_branches" ON ("scm_branch"."id" = "scm_branchgroup_branches"."branch_id") LEFT OUTER JOIN "scm_branchgroup" ON ("scm_branchgroup_branches"."branchgroup_id" = "scm_branchgroup"."id") WHERE "scm_branchgroup_branches"."branch_id" IS NULL LIMIT 1 Is orders of magnitude faster: Limit (cost=1518.71..1533.35 rows=1 width=145) The difference is with the WHERE clause. Django generates WHERE "scm_branchgroup"."id" IS NULL, but a properly optimized query should use WHERE "scm_branchgroup_branches"."branch_id" IS NULL. This is because Postgres recognizes the second query as a anti-join query and can do a lot of optimization. The basic question is: How do I make Django generate a faster query? Thanks Dmitry -- 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.
custom management command with multiple required parameters
Hi, I just want to make sure I'm not missing something obvious. I'm writing a command that takes multiple required parameters and a set of optional parameters and I there doesn't seem to be readily available support for this use case. LabelCommand can take multiple labels, but the semantics of the labels are such that they are assumed to be independent of each other and are really equivalent to two invocations of the command each with its own label. At the moment, I'm simply using BaseCommand and handling parameters manually in the handle() method. I want to know if there is something I'm missing that would give me out-of-box support of multiple required parameters (like validation, assignment to local variables, etc.). E.g. class Command(ParametrizedCommand): help = 'Kick off a node analysis task for a given path in a repository' args = ' ' def handle_parameters(self, repo_name, path, **options): pass Thanks Dmitry -- 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.
CAS and Django cache
Can I do check-and-set operations using Django's cache api? Thanks D. -- 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: direct query to Oracle db view doesn't work
I'm starting to doubt this is a Django issue. Double check that you are connecting to the database/schema you *think* you are connecting to and you are using the use account you *think* you are using :) D. On Oct 19, 11:46 am, msbuck <mbuckn...@usgs.gov> wrote: > I just tried it and it doesn't. If I try an aggregate query such as > using COUNT(account_number) without the Where clause, I get a row with > 0 in it (there are thousands of account_numbers). > > Thanks for the suggestion. > > On Oct 19, 1:30 pm, dmitry b <dmitry.ma...@gmail.com> wrote: > > > > > > > > > see if a pamaterized query works: > > > cursor.execute('SELECT account_number FROM vw_billed_summary_fact > > WHERE ippa=%s', ['col11-emnj00-1147']) > > > d. > > > On Oct 19, 8:25 am, msbuck <mbuckn...@usgs.gov> wrote: > > > > I'm having another strange problem. I'm executing SQL statements > > > directly rather than using the ORM and it is working fine except when > > > I query one particular view. Then the query returns nothing. I can > > > execute the same query from python by using the cx_Oracle module > > > directly and it returns what I expect. Below is an example of what I'm > > > doing in the Django code (within a view): > > > > cursor = connection.cursor() > > > cursor.execute('SELECT account_number FROM vw_billed_summary_fact > > > WHERE ippa=\'col11-emnj00-1147\'') > > > > This should produce a single row and instead produces no rows. I've > > > tried using the COUNT aggregate to return the number of rows and this > > > also returns zero. I don't get errors ... just no data. > > > > If I run a little python script that creates the connection directly > > > using cx_Oracle and execute the query I get the expected result. > > > > Note that queries on other views and tables in the database work. Any > > > thoughts on what I'm doing wrong? > > > > 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.
Re: direct query to Oracle db view doesn't work
see if a pamaterized query works: cursor.execute('SELECT account_number FROM vw_billed_summary_fact WHERE ippa=%s', ['col11-emnj00-1147']) d. On Oct 19, 8:25 am, msbuckwrote: > I'm having another strange problem. I'm executing SQL statements > directly rather than using the ORM and it is working fine except when > I query one particular view. Then the query returns nothing. I can > execute the same query from python by using the cx_Oracle module > directly and it returns what I expect. Below is an example of what I'm > doing in the Django code (within a view): > > cursor = connection.cursor() > cursor.execute('SELECT account_number FROM vw_billed_summary_fact > WHERE ippa=\'col11-emnj00-1147\'') > > This should produce a single row and instead produces no rows. I've > tried using the COUNT aggregate to return the number of rows and this > also returns zero. I don't get errors ... just no data. > > If I run a little python script that creates the connection directly > using cx_Oracle and execute the query I get the expected result. > > Note that queries on other views and tables in the database work. Any > thoughts on what I'm doing wrong? > > 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.
collectstatic in RPM install
Hi, For deployment to production, I package my Django app into an RPM package. The install script is responsible for installing dependencies, copying files, etc. Now that I've switched to Django 1.3 I also want to run the collectstatic command as part of the deployment script. To do this, I've added the following to the spec: %post # collect static files %{__python} %{installpath}/src/scam/manage.py collectstatic --noinput The problem is that the command doesn't run from inside RPM. Running with -vv, I can see python being kicked off and I actually get a couple of standard warning messages from Django. That's it, though. There is no list of files being copied and in the end, the static directory isn't being created/populated. Has anyone successfully tried incorporating collectstatic into an RPM- based deployment? RHEL 5.5 RPM 4.4.2.3 Python 2.6 Django 1.3.1 Thanks Dmitry -- 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.
name conflicts in static files
Hi, With the new way of handling static files in Django 1.3 what would happen if two applications have identically named static files? E.g.: |___ app1 | | static | |_ styles.css |___ app2 | static |_ styles.css Thanks Dmitry -- 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: check for existence in bulk
thanks, that's what I ended up using. On Mar 30, 11:58 am, Jason Culverhousewrote: > You could use values_list and flat as in: > > User.objects.filter(username__in =['jason', 'was', > 'here']).values_list('username', flat=True) > > returns a list: > > [u'jason', u'was'] > > After that you can figure out the best way to perform the lookup. > -- 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.
check for existence in bulk
Hi, is there a way to check in bulk for record existence and get back a map of results similar to what's returned by in_bulk(). In my case, I need to look up records by a unique field which is not the primary key and I don't want object instances back, just true or false. Thanks Dmitry -- 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: Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set
you need to be also using RequestContext in your view instead of the regular Context. What does your view method's return statement look like? On Dec 28, 7:02 am, Lee Connellwrote: > I didn't have TEMPLATE_CONTEXT_PROCESSORS at all, I copied the code > and it did not help, MEDIA_URL is still blank. I am using django 1.2.1 > on windows. > > On Dec 28, 12:56 am, Kenneth Gonsalves wrote: > > > > > > > > > On Mon, 2010-12-27 at 08:03 -0800, easylancer wrote: > > > TEMPLATE_CONTEXT_PROCESSORS = ( > > > 'django.contrib.auth.context_processors.auth', > > > 'django.core.context_processors.debug', > > > 'django.core.context_processors.i18n', > > > 'django.core.context_processors.media', > > > 'django.contrib.messages.context_processors.messages', > > > 'django.core.context_processors.request', > > > ) > > > actually only 'request' is not there - the others are present by default > > -- > > regards > > KGhttp://lawgon.livejournal.com > > Coimbatore LUG roxhttp://ilugcbe.techstud.org/ -- 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.
Re: Suspending tasks in response to a systematic transient error
Woops, sorry, please ignore. I posted this to a wrong group. -- 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.
Suspending tasks in response to a systematic transient error
Hi, Let's say I have several hundred instances of a task waiting in a queue and this task needs a database connection to complete successfully. Somewhere along the way the database goes down, so tasks are starting to fail one after another. When this happens (say when ), is there a way to suspend processing of the remaining tasks? Thanks Dmitry -- 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.
Re: registering app level signal handlers
On Dec 18, 1:44 am, Łukasz Rekuckiwrote: >[...]The problem with putting signal handlers > in __init__, is that it isn't the place you would really expect Model > related code to live (like post_save). It can also lead to non-obvious > cyclic imports, 'cause your handler code will most likely need some > models, etc. Cyclic imports is exactly the problem I've run into. I do currently keep the signal handler registration code in __init__.py because that the only place as far as I can tell is guaranteed to be executed at Django's initialization. But because of cyclic dependencies, I had to move all other code out of __init__.py. Sounds like Django needs an init.py for every app that will be executed after all imports are done. -- 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.
Re: registering app level signal handlers
Aren't an app's models loaded lazily (upon the first use)? On Dec 16, 7:16 pm, "W. Craig Trader"wrote: > I usually register the signals for a given application at the bottom of that > app's model.py file. > > - Craig - -- 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.
Re: registering app level signal handlers
On Dec 16, 3:28 pm, Graham Dumpleton <graham.dumple...@gmail.com> wrote: > On Friday, December 17, 2010 10:00:55 AM UTC+11, dmitry b wrote: > > Are you talking about UNIX process signals? I'm sorry, I forgot there are two ways to interpret my question. It is about Django signals. -- 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.
registering app level signal handlers
Hi, What is the best place to register a signal handler so that the registration happens when the app is first initialized into django? I have an app that needs to listen to signals generated by another app and fire off celery tasks in response. I've tried placing the registration code into the app's __init__.py, but since I have other reusable code there, doing so created cyclical references when importing modules. Is there another location within the app's code that is guaranteed to be picked up when django is being initialized (like an django app level init rather than python level module init)? Thanks Dmitry -- 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.
FileField and location and storage
Hi, I've written a custom Storage that uses WebDAV as its underlying engine. When I save a file '/foo/bar/file.ext', I want it to be saved under /foo/bar in the webdav filesystem. However, it seems that FileField overrides the directory structure: def generate_filename(self, instance, filename): return os.path.join(self.get_directory_name(), self.get_filename(filename)) where get_directory_name() is defined as def get_directory_name(self): return os.path.normpath(force_unicode(datetime.datetime.now().strftime(smart_str(self.upload_to I'm not really sure why FileField finds it appropriate to impose its own directory structure on the underlying storage engine. But short of creating a custom subclass of FileField and overriding generate_filename and/or get_directory_name(), is there a different way of preserving the original file location path? Thanks Dmitry -- 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.
handling generated files
Hi, How do I use Django's FileField with autogenerated files? That is, these files aren't uploaded by a user, but rather are created on the fly. I've looked at ContentFile, but this class doesn't seem to have a way to attach a file name (the name is also computed at run-time based on some criteria). Do I need to write my own implementation of File for this or am I missing an existing class? Thanks Dmitry -- 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.
disabling session management for certain requests
Hi, My application has both stateful and stateless (REST) views. Stateful views primarily back browser-based GUI, while stateless are for RESTful service requests. Is there a way to disable session management for the stateless requests? Thanks Dmitry -- 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.
transactions in management commands
Hi, What's the default transaction mode for django management commands? Thanks Dmitry -- 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.
expressions in values()
Hi, I have the following query: AnalyzedFile.objects.filter(bug_signature__bug_condition__tracked_change=cr).values("scm__path") In other words, the result is a list of AnalizedFile.scm.path values. I'd like to change the query so that the returned value is a combination of two fields: scm.path + "#" + scm.revision. So far I haven't been able to figure out how to do this. I've looked at using extra(): AnalyzedFile.objects.filter(bug_signature__bug_condition__tracked_change=cr).extra(select={'path':"..."}) The problem with this approach is that I don't know how to refer to the fields of the table representing the "scm" relationship. Since that table is part of a join and Django auto-generates table aliases, I wouldn't now what to prefix the column names with. Any thoughts? BTW, this query is later used inside of another query (resulting in a nested select), so I need to do the path/revision concatenation in SQL. Otherwise, I would've done it easily in python. Thanks Dmitry -- 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.
Re: enumerating view functions
Oops. Didn't see you reply. Thanks, I'll take a look at the command extension. BTW, the second link you provided is my own snippet :) I want to improve it with auto documentation extracted from the actual view functions. On Jun 16, 11:40 am, Alexis Rodawrote: > En/na Dmitry Beransky ha escrit: > > > Hi, > > > Is there a way to enumerate view functions that are currently > > associated with a url patern? In the end, I'd like to get a list of > > triples: pattern name, pattern, callback function. > > If you want to get a dump of the (regex, view, name) triples on the > screen take a look at django-command-extensions[1], command 'show_urls'. > > If you want to get the list from your app in order to do some processing > on it [2] provides a simple example on how to "introspect" the URLs. > > [1]http://code.google.com/p/django-command-extensions/ > [2]http://djangosnippets.org/snippets/2059/ > > HTH -- 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.
Re: db autoclobbering with automated tests
So, no one is running automated tests? On May 24, 4:16 pm, dmitry b <dmitry.ma...@gmail.com> wrote: > Hi, > > I'm in the process of setting up automated selenium tests for a django > app using Hudson. As part of the build script, I'm starting up a test > server: > > $> python manage.py testserver --addrport 0.0.0.0:8080 ../../test/gui/ > seed_data.json > > However, when this line runs, I get the following message: > > ('42000', "[42000] [Microsoft][ODBC SQL > Server Driver][SQL Server]Database 'test_Tools' already exists. > Choose a different database name. (1801) (SQLExecDirectW)") > Type 'yes' if you would like to try deleting the test database > 'test_Tools', > or 'no' to cancel: Traceback (most recent call last): > > I see that the test apis have an option to autoclobber the database. > However, I cannot find a way to tell django to just quietly recreate > the database from the command line. What am I missing? -- 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.
db autoclobbering with automated tests
Hi, I'm in the process of setting up automated selenium tests for a django app using Hudson. As part of the build script, I'm starting up a test server: $> python manage.py testserver --addrport 0.0.0.0:8080 ../../test/gui/ seed_data.json However, when this line runs, I get the following message: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Database 'test_Tools' already exists. Choose a different database name. (1801) (SQLExecDirectW)") Type 'yes' if you would like to try deleting the test database 'test_Tools', or 'no' to cancel: Traceback (most recent call last): I see that the test apis have an option to autoclobber the database. However, I cannot find a way to tell django to just quietly recreate the database from the command line. What am I missing? Thanks D. -- 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.