Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
> Just create your own Manager and override the default (named 'objects') in > your models. Have 'get' behave any way you like. > > http://docs.djangoproject.com/en/1.1/topics/db/managers/ > > Shawn Ding! http://docs.djangoproject.com/en/1.1/topics/db/managers/#adding-extra-manager-methods luv

Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
> The only condescension I've seen in this thread is from you. And, to > be fair, if I wanted to be condescending I'd have simply pointed you > at Tony Hoare's explanation of null values That's why I said NullObject, in the first post. -- You received this message because you are subscribed to t

Re: Adding a new convenience filter 'contains_any'

2010-03-04 Thread Phlip
Peter Herndon wrote: > Won't the "in" filter do exactly what you need? > > http://docs.djangoproject.com/en/1.1/ref/models/querysets/#in Why do you need even __in? Given... Entry.objects.filter(id__in=[1, 3, 4]) ...couldn't id=[] overload if the target is

Re: Adding a new convenience filter 'contains_any'

2010-03-04 Thread Phlip
;list's) in fields, the =[] event is free to be "overloaded" by its type. So id=[] would resolve to id__in=[], id=Scalar to id__exact=Scalar, and the explicit versions are available if you suspect that overloading is fragile. (I also disagree with leaving out the spaces around =, but obvi

Re: Adding a new convenience filter 'contains_any'

2010-03-05 Thread Phlip
On Mar 5, 8:41 am, Peter Herndon wrote: > On Mar 4, 2010, at 7:37 PM, Phlip wrote: > > (I also disagree with leaving out the spaces around =, but obviously > > obeying a team style guide supersedes improving it...) > > ... the goal of clarity/legibility uh... -- You

Re: Adding a new convenience filter 'contains_any'

2010-03-05 Thread Phlip
> >>> (I also disagree with leaving out the spaces around =, but obviously > >>> obeying a team style guide supersedes improving it...) > > >> ... the goal of clarity/legibility > > > uh... > > ;)  I meant *having* a style guide was consistent with said goal. right - following an aesthetic style g

Re: Adding a new convenience filter 'contains_any'

2010-03-08 Thread Phlip
> In this case, it's not just a team style guide - it's PEP8, which clearly > says: And if the PEP8 told you to ... just jump off a cliff... would you? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django

Re: Adding a new convenience filter 'contains_any'

2010-03-08 Thread Phlip
> > And if the PEP8 told you to ... just jump off a cliff... would you? > > Sounds like you might benefit from actually reading it: This thread arc is about me lamenting the positive value of style guides, even those with wrong line-items. Nobody here has said to get creative with any style guide

SNIPPET: assert_model_changes(record, 'field', 41, 42, lambda: money_line())

2010-03-10 Thread Phlip
eval() a string instead of serve an attribute? self.assert_model_changes( blog, 'post.count()', 41, 42, lambda: blog.write_one_post('yack yack yack') ) The code shows how to .reload() in Django, because (unless I'm wrong), Django models don't ha

def reload(model): model.__dict__ = model.__class__.objects.get(pk=model.pk).__dict__ ; return model

2010-03-10 Thread Phlip
ort (or fail to prevent) assigning a .__dict__ like that? -- Phlip http://c2.com/cgi/wiki?ZeekLand -- 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 fr

Re: def reload(model): model.__dict__ = model.__class__.objects.get(pk=model.pk).__dict__ ; return model

2010-03-11 Thread Phlip
iously - reload(instance) does nothing to the instance we already have, and its internals are still dirty... -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send emai

Re: PyCharm IDE - Anyone using it yet

2010-03-12 Thread Phlip
ecades do we have to wait until editors support testing as aggressively as debugging? -- Phlip http://penbird.deviantart.com/art/Uncle-Wiggily-Wants-You-156969773 -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this

Re: Negate querysets

2010-03-22 Thread Phlip
> Just create another queryset that excludes everything in your first > queryset: > > negated_queryset = User.objects.exclude(id__in=queryset.values("id")) QuerySets are already so easy to plug-n-play... Ain't there a way to do it without whacking the database twice?

Re: Negate querysets

2010-03-23 Thread Phlip
"SELECT * WHERE id not in (SELECT id WHERE ...)" might just snocker the database worse than two SELECTs. You never know; that's why I'd like to see an EXPLAIN on it! -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You received this message because you are subscribed to the Googl

Re: Negate querysets

2010-03-23 Thread Phlip
> I want to be able to answer your question, forever. Is there a way, > from a developer test, to query "what SQL statement does this QuerySet > generate"? Oh, duh, it's QuerySet.query, as a string. Brand X makes that one inconceivably hard, due to poor factoring... >

assert_performant(query_set)

2010-03-23 Thread Phlip
at, I have used this technique, copiously, on other projects, and whenever that assertion failed it indeed saved us from accidentally deploying a slow SQL statement to our server! -- Phlip http://zeekland.zeroplayer.com/Pigleg_Too/1 -- You received this message because you are subscribed to t

Re: assert_performant(query_set)

2010-03-24 Thread Phlip
orrect, we will pin down their behavior if we parse back the intermediate value - the actual SELECT statement, and then interrogate it. Oh, yeah, and such a test is also perform...ing. Well. Because it doesn't build records or read them. I will see when I have time to code that up... -- Phlip

new_records = assert_latest(query_set, lambda)

2010-03-24 Thread Phlip
#x27;s only one - we sample the lambda source, to make the error message as clear as possible; this works best if the lambda's on its own line - every assert needs a deny; I will write deny_latest as soon as a need appears. -- Phlip http://zeekland.zeroplayer.com/Pigleg_Too/

automatically import lots of modules at python manage.py shell time?

2010-03-26 Thread Phlip
. How can we fix the first problem? How can this (otherwise useful) shell use a minimal or invisible import rubric, to grab, say, a bunch of models so they are all ready & available for use? -- Phlip http://penbird.deviantart.com/ -- You received this message because you are subscribed to

Re: automatically import lots of modules at python manage.py shell time?

2010-03-26 Thread Phlip
local_dict[model_class.__name__] = model_class del local_dict, appcache, os ''') os.system('ipython -i -nobanner .ipython') -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You received this message because you are subscribed to the Google Groups "Django users"

Re: Testing email with the testserver

2010-03-26 Thread Phlip
;s why the documentation assumed you started there. -- Phlip -- 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-us

Re: assert_performant(query_set)

2010-03-29 Thread Phlip
> qs.query.get_compiler(qs.db).as_sql() That gives this error message with the usual zero Google hits for that error message: AttributeError: 'BaseQuery' object has no attribute 'get_compiler' -- You received this message because you are subscribed to the Google Groups "Django users" group.

Re: assert_performant(query_set)

2010-03-29 Thread Phlip
>   AttributeError: 'BaseQuery' object has no attribute 'get_compiler' qs._as_sql() returns a tuple of a SELECT statement, and a (), presumably with wildcards; I will start there. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this

Re: assert_performant(query_set)

2010-03-29 Thread Phlip
>  * Similarly, connection.cursor() will only work in the single > database case. connections[qs.db].cursor() Aaaand that's not working either. (No connections, no qs.db.) I must take a break until someone unravels all this, because I don't know enough about the architecture inside QuerySet... -

Re: How to share settings file in multiprogrammer project

2010-03-29 Thread Phlip
e one copied up to the server. All sub-settings files should start with from settings import * to pull in the common settings, and should override them if they need to. One important override is test_settings should use sqlite3 :memory: database. -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You

Re: How to share settings file in multiprogrammer project

2010-03-29 Thread Phlip
> The test_settings and dev_settings should point to a PASSWORDLESS > database with localhost-only permissions. The production_settings file > should not be committed. It's the one copied up to the server. Come to think of it, what I'm screaming about here is three separate things: - developer d

Re: I am having issues with django test

2010-03-29 Thread Phlip
>     def setUp(self): >         user = User.objects.create_user(USER, '@nowhere.com', PASS) That's what fixtures are for! -- 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. T

Re: assert_performant(query_set)

2010-03-29 Thread Phlip
do with Django - is ... cursor.execute('EXPLAIN ' + query) ...seems to scramble a sqlite3 database. If I take the EXPLAIN out I don't get unrelated test failures (tho the new assertion naturally does not work!). I will make it work for MySQL! -- Phlip -- You received this message becaus

assert_compliant_sql

2010-03-30 Thread Phlip
tput The source appears below my sig (where I am aware archivers might trim it). Warning: Per my other thread, calling EXPLAIN on an a SQLite3 connection seems to scramble it. Not sure why, but I don't care, because one should not use SQLite3 in production. -- Phlip http://c2.com

Re: How do I properly unit test a Django session?

2010-03-31 Thread Phlip
E_NAME] = store.session_key session = self.client.session session.update(dictionary) session.save() # and now remember to re-login! -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You received this message because you are subscribed to the Google Groups "Django users

manage.py loaddata silently fails

2010-04-12 Thread Phlip
Djangoists: (Under version 1.1.1) loaddata (and the fixtures= line in tests) silently fails if the data cannot load. How do I access the error message? -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You received this message because you are subscribed to the Google Groups "Django

Re: manage.py loaddata silently fails

2010-04-12 Thread Phlip
warning. The fixtures= line also has this bug. -- Phlip -- 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

what lines in the templates are culpable?

2010-04-12 Thread Phlip
Djangoists: When code below a template throws an error, we get an insanely detailed stack trace of all the lines AROUND the template. How do I tell what lines INSIDE the templates caused the error? -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You received this message because you are

Re: what lines in the templates are culpable?

2010-04-12 Thread Phlip
> Uusually the first line in the traceback tells you pretty explicitly > where the error is. Without the traceback, it's hard to say where your > problem lies. One of the templates is "basket.html", and "basket.html" does not appear in the transcript. All the lines are only django's internal rend

Re: what lines in the templates are culpable?

2010-04-12 Thread Phlip
> If you posted some specifics of what you are actually seeing, someone might > be able to help. I mean, actually copy-paste the traceback into your post > (or put it someplace like dpaste.com and point to it). I am not asking "oo help I can't get my template working". That part's done - by clampi

how to get the test runner to only rebuild & populate the test_database if it changed?

2011-05-11 Thread Phlip
ere an easier way, or has someone already done this? (1.2, BTW - the obese database prevents an upgrade to Django 1.3!) -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this grou

Re: how to get the test runner to only rebuild & populate the test_database if it changed?

2011-05-11 Thread Phlip
" database. It does not even change the file time on the .db file when the tests run. Could someone better at Django internals than me package this system up and contrib it? -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You received this message because you are subscribed to the Google Grou

cascading create

2011-01-31 Thread Phlip
to optimize the database calls. If not, that's okay to. Google doesn't say Django can do this. My specific problem is I have a dozen trees with a couple thousand leaves each, and simply writing them all causes a bottleneck. --   Phlip   http://c2.com/cgi/wiki?ZeekLand -- You rec

Re: cascading create

2011-02-01 Thread Phlip
Bump? String together the SQL myself? On Jan 31, 3:40 pm, Phlip wrote: > Djangoists: > > Given a model Tree with many Leaves, I want to write this: > >   t = Tree(data=42) >   t.leaves.add(leafy_data=43) >   t.leaves.add(leafy_data=44) >   t.save() > > I want the s

How to pivot a table?

2011-02-17 Thread Phlip
n re-pack the array with a for-loop. Do QuerySet aggregations and annotations offer some way to push that query into the database? -- Phlip http://c2.com/cgi/wiki?ZeekLand -- You received this message because you are subscribed to the Google Groups "Django users" group.

Re: Unit Testing: temporarily altering django settings

2011-02-17 Thread Phlip
o trivially pass it, without real user input. To test the captcha, mock it to pass or fail. -- Phlip http://c2.com/cgi/wiki?ZeekLand -- 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@

order_by clause to preserve order in list? - redux

2011-02-21 Thread Phlip
s.google.com/group/django-users/browse_thread/thread/f23b2bdf24ff7a26/110d3e5c9e69ca63 I will, of course, start with extra(), and see where that takes me! -- Phlip http://zeekland.zeroplayer.com/ -- You received this message because you are subscribed to the Google Groups "Django users"

Re: Unit Testing: temporarily altering django settings

2011-02-21 Thread Phlip
On Feb 21, 12:47 pm, Cody Django wrote: > Thanks -- I didn't know about mock objects, and this is good to know. > But this doesn't feel like this is the solution I'm looking for.  It's > a large project, and your proposal would require extensive patching. Does your project access the CAPTCHA set

Re: Select x random rows from DB

2011-02-21 Thread Phlip
On Feb 20, 2:19 pm, galago wrote: > What is the best way, to select X random rows from DB? I know that > method: .all().order_by('?')[:X] is not good idea. > What methods do you use? order_by('RAND()') That might use the same seed each time. To create, for example, a rotating home page with

Re: order_by clause to preserve order in list? - redux

2011-02-21 Thread Phlip
eniences" as the .order_by() builder. It insisted on parsing my string instead of simply appending it. > -- >   Phlip >  http://zeekland.zeroplayer.com/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this grou

Field forced to not-null

2018-08-06 Thread Phlip Pretorius
the null=True. Any idea why this is happening? I have deleted the complete Django project and started from scratch only to find the same scenario; when I click save, I get the following message. Any advice will be welcomed. Regards, Phlip -- You received this message because you are subs

Re: Field forced to not-null

2018-08-09 Thread Phlip Pretorius
Thank you Andréas and Jason That solved my problem Regards, Phlip On Monday, August 6, 2018 at 3:02:01 PM UTC+2, Andréas Kühne wrote: > > Hi Philip, > > The field is required because you haven't allowed it to be blank - and > django admin requires fields to have the fol

Recursive one-to-many foreign key on the same table

2018-08-09 Thread Phlip Pretorius
== I get the following error message: no such column: komadm_apps_decisionindex.IndexPredecessor_idno such column: Any help will be welcome. Regards, Phlip -- You received this message because you are subscribed to the Google Groups "Django users" group.

Re: Recursive one-to-many foreign key on the same table

2018-08-10 Thread Phlip Pretorius
Thank you Marius; the video is worth the watch and thought provoking Phlip On Thursday, August 9, 2018 at 2:42:13 PM UTC+2, Phlip Pretorius wrote: > > I want to build a one-to-many recursive foreign key on a table in Django. > > The concept is something like this: > > T

<    1   2