Re: modelformset_factory, initial, and queryset

2010-10-17 Thread Tim Valenta
> The only thing I can think of is that the choices for the field are > not being set correctly to start with - in the bit where you write > `(choices=[yada yada]`, what is 'yada yada'? Obviously, this must > contain *all* possible values for the codes across all responses, so > that the relevant

Re: modelformset_factory, initial, and queryset

2010-10-17 Thread Tim Valenta
, Tim Valenta <tonightslasts...@gmail.com> wrote: >> The only thing I can think of is that the choices for the field are >> not being set correctly to start with - in the bit where you write >> `(choices=[yada yada]`, what is 'yada yada'? Obviously, this must >>

Re: modelformset_factory, initial, and queryset

2010-10-15 Thread Tim Valenta
ue for any of the objects' "codes" field is empty. On Oct 14, 3:09 am, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Oct 14, 10:32 am, Tim Valenta <tonightslasts...@gmail.com> wrote: > > > > > > > > > > > This is driving me mad, so I must as

modelformset_factory, initial, and queryset

2010-10-14 Thread Tim Valenta
This is driving me mad, so I must ask the community, in hopes of a workaround: I've got a simple formset of models on a page, generated by modelformset_factory. This particular page will never create forms-- it only modifies existing ones. Therefore the queryset I pass into the formset

Blank Admin changelist with list_display FK

2010-03-16 Thread Tim Valenta
I've noticed this a few times in my code, and it seemed to come and go as an issue: Using various revisions from the SVN trunk over the last 4 months, the following has caused my admin changelist view for a model to go completely blank: # events/models.py class Event(models.Model):

Re: PicklingError with Queryset Refactor

2010-02-24 Thread Tim Valenta
a piece of my code, since the development server tricked me into thinking that I could pickle those QuerySets. On Feb 24, 8:14 pm, Tim Valenta <tonightslasts...@gmail.com> wrote: > There was a topic on this a couple of years ago, and it seems to still > be around.   >

PicklingError with Queryset Refactor

2010-02-24 Thread Tim Valenta
There was a topic on this a couple of years ago, and it seems to still be around. (Original: http://groups.google.com/group/django-users/browse_thread/thread/32143d024b17dd00?pli=1) An exception is raised when trying to use the low-level caching API on a QuerySet. I read from the mentioned

Re: Directories inside app directory

2009-12-16 Thread Tim Valenta
I wanted to echo what Bill has just said. One simple (yet effective) reason why allowing multiple models/views in a single file is handy is because you get to remove lots of duplicate code surrounding imports and utility functions. Bill's process should be able to work, theoretically. You may

Re: How do I filter an InlineModelAdmin ForeignKey?

2009-12-16 Thread Tim Valenta
Well, you're probably getting the error on your 'extra' inlines. self.instance is unbound in that case, and so self.instance.providers cannot be looked up. I wrote a little thing to fetch a proper object though... just be sure to include your parent model's field in your fields on the inline.

Re: Save as new and files

2009-11-27 Thread Tim Valenta
Does the newly created model lack a path entirely, or does it have a path that points to a false location? In other words, is the right path making it to the database, yet not to the filesystem to copy the file? Also, since you didn't mention anything about it, I would remind you that a proper

Re: Cannot assign None, does not allow null values

2009-11-27 Thread Tim Valenta
You've got a lot of models in that file. Which one are you trying to save when it throws the error? By the way, I notice that your "ItemWithMedia" class is probably creating a database table.. if you never need to manipulate it direct (ie, you only make subclasses of it), I might suggest putting

Re: CSRF gone haywire

2009-11-27 Thread Tim Valenta
have been a hundred times harder to figure out if I were a not a native speaker of English. I can handle a few of those, like IMHO, but I can't say that I've come across "AFAIK" often enough to compute that in record time. Tim On Nov 27, 10:22 am, Tim Valenta <tonightslasts...@gmail.com&

Re: CSRF gone haywire

2009-11-27 Thread Tim Valenta
gmail.com> wrote: > 2009/11/27 Tim Valenta <tonightslasts...@gmail.com>: > > > > > > > Has anybody else experienced a senseless failure of the dev trunk's > > CSRF verification?  Very suddenly this morning, Django won't let me > > change anything in

CSRF gone haywire

2009-11-27 Thread Tim Valenta
Has anybody else experienced a senseless failure of the dev trunk's CSRF verification? Very suddenly this morning, Django won't let me change anything in my admin sites. I didn't update my copy of the SVN trunk, but as soon as I took myself off of the admin-ui branch, it flipped out. Step by

Re: Issue when saving a model form

2009-11-27 Thread Tim Valenta
Try overriding your AddRestaurantForm's "save" method: def save(self, commit=True): self.instance.city = get_object_or_404(City, name=self.instance.city) # Finish by passing control back to the normal Django flow: super(AddRestaurantForm, self).save(commit) I think

Re: add permission by name instead of number

2009-11-27 Thread Tim Valenta
You can expand your .add() statement slightly, by passing it an object instead of an id: request.user.user_permissions.add(Permission.objects.get(name='some permission name')) You could alternatively do a lookup with the "codename='some_name'" instead of the human-readable name. The codename is

Re: distinct related objects

2009-11-27 Thread Tim Valenta
It looks like the problem is that you're trying to group by Technology, but your queryset is in Projects. You could experiment with the "regroup" template tag ( http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup ) It's a little hard to understand at first, but I think it's

Re: How can I change the values of select options created by a ModelForm?

2009-11-27 Thread Tim Valenta
You could tell Django to designate the 'code' field as the primary key, which will automatically make it unique. Any forms will then be forced to identify by the code, rather than some numeric id: class Country(models.Model): code = models.CharField(max_length=5, primary_key=True)

Re: better error handling in templatetags?

2009-11-27 Thread Tim Valenta
spite* us all. Sorry :) On Nov 27, 8:27 am, Tim Valenta <tonightslasts...@gmail.com> wrote: > Django is forced to catch your errors, and then bubble them back up to > you.  If you notice, none of the traceback lines are even in your > code-- it's all in Python libs or an Django c

Re: better error handling in templatetags?

2009-11-27 Thread Tim Valenta
Django is forced to catch your errors, and then bubble them back up to you. If you notice, none of the traceback lines are even in your code-- it's all in Python libs or an Django code. The issue is that you're not seeing raw exceptions, but instead you're seeing reproduced exceptions. I agree

Re: More media collection nightmares

2009-11-25 Thread Tim Valenta
clude the jsi18n and > core.js on every page as part of the base template. > > So far so good.  Hopefully I won't find any more widgets with surprise > dependencies. > > -Todd Blanchard > > On Nov 25, 2009, at 12:14 PM, Tim Valenta wrote: > > > > > Is it a wi

Re: Accessing model instance on pre_save signal

2009-11-25 Thread Tim Valenta
I know how messed up this all seems, so I sympathize. I totally want to store items according to a related object's name or id or whatever. However, I'm using upload_to in a more straightforward manner, and it seems to work out alright. Tell me if you've already tried it this way: class

Re: middleware to log request/response objects for testing purposes?

2009-11-25 Thread Tim Valenta
http://code.google.com/p/django-logging/ *shrug* I haven't used it, but he's got a screen-cast about how the thing is set up. He builds it off of built-in Python logging modules. It looks like it provides some decorators for suppressing logging output on methods, etc. Might be worth the time

Re: Is it possible to 'order' the left side of a filter_horizontal?

2009-11-25 Thread Tim Valenta
Well, you've got a couple of options. One is easiest and most straightforward, but could impact performance. The second is a little bit more work, but would limit the ordering to only taking effect on that one form. The first way is to use the Meta option `ordering = ('fieldname',)`, as

Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Tim Valenta
> > On Nov 25, 3:04 pm, Stodge <sto...@gmail.com> wrote: > > > > > I can successfully start python and import the settings file. My > > settings file only imports os. > > > On Nov 25, 3:01 pm, Tim Valenta <tonightslasts...@gmail.com> wrote: > > >

Re: More media collection nightmares

2009-11-25 Thread Tim Valenta
It looks to me like the Media class managing the files stores JS files in a Python list, so order should be remembered. I can see the issue though if a *widget* has critical "core" media, which isn't rendered until after other bits of media already went out the hatch. Is it a widget that has the

Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Tim Valenta
Well, does it have errors? If you navigate to the directory where it's kept, can you enter the python shell and do "import settings"? Given all of the trouble you're having, can you verify that it imports successfully? The settings module itself should have no immediate dependencies, unless

Re: applying a patch

2009-11-25 Thread Tim Valenta
It's meant to be done through an SVN checkout, since that's the format that the Django development repository is kept. If you haven't got SVN, I'd start there. If you're on Windows, the "nicest" solution is "tortoisesvn", which integrates pretty simply into the Windows shell for easy right-click

Re: Sick of defining urls

2009-11-25 Thread Tim Valenta
I usually don't find myself writing too many redundant views, since the built-in admin site does so much of that automatically. Then I just build views specific to the site's public UI. I still find it curious that you would find yourself recreating said urls. I run a company database through

Re: Form foreign key add new

2009-11-25 Thread Tim Valenta
> I don't know what to replace XXX with, I know it's a db_field > but I don't > know how/where to get it from. AutoFields are the auto-incrementing primary key of your model. By default, your models get an automatic "id" attribute, which is what this is. Django frequently deals with the raw

Re: string-based fields and null

2009-11-25 Thread Tim Valenta
In most cases, any string field should be allowed to be blank, and can easily survive WITHOUT "null=True". As stated before me, this is preferable. For instance, you asked about FileField, among others. This is perfectly fine to only use "blank=True". You'll primarily only be using "null=True"

Re: reversing URLs

2009-11-25 Thread Tim Valenta
ight track, but is there anything else that you could add about the dependency I've noted? Thanks, Tim On Nov 24, 10:39 pm, Tim Valenta <tonightslasts...@gmail.com> wrote: > Holy cow you're right.  That was an extreme case of needing another pair of > eyes.  I thought I had tested the view a

Re: settings.py seems to be cached or stuck

2009-11-25 Thread Tim Valenta
ov 24, 10:55 pm, Graham Dumpleton <graham.dumple...@gmail.com> wrote: > On Nov 25, 3:58 pm, Karen Tracey <kmtra...@gmail.com> wrote: > > > > > > > On Tue, Nov 24, 2009 at 11:32 PM, Tim Valenta > > <tonightslasts...@gmail.com>wrote: > >

Re: calendar.js can't find variable gettext

2009-11-25 Thread Tim Valenta
On Nov 24, 10:32 pm, Todd Blanchard wrote: > Yep, I solved this by ripping and copying some code out of admin/sites.py > and adding a url conf for it. > > It works now, but this should be included by default through the widget media > dependency system.  Not very slick.  I

Re: reversing URLs

2009-11-24 Thread Tim Valenta
! On Nov 24, 2009, at 10:33 PM, Karen Tracey <kmtra...@gmail.com> wrote: On Tue, Nov 24, 2009 at 11:20 PM, Tim Valenta <tonightslasts...@gmail.com>wrote: > Thanks for the reply. Yes, I can give a bit more info on it. > > So, for starters, my (abbreviated) mai

Re: Best way to use django for sql with raw LIKE statement

2009-11-24 Thread Tim Valenta
It sounds like you've been using the right sorts of methods for that job, but the complexity of the query is getting to be too much :) There's a 'regex' lookup... http://docs.djangoproject.com/en/dev/ref/models/querysets/#regex That's a pretty intense example text parsing search. I think the

Re: settings.py seems to be cached or stuck

2009-11-24 Thread Tim Valenta
opment. > > Tom > > On Nov 25, 2:24 am, Tim Valenta <tonightslasts...@gmail.com> wrote: > > > > > Are you using the development server?  There's definitely caching > > funny-business in a production web server, but that should affect you > > if you're

Re: reversing URLs

2009-11-24 Thread Tim Valenta
anges don't seem to make any difference. Any thoughts? I'm pretty sure there's no more info to give... the full traceback stays in Django files, never directly touching my own, and doesn't reveal anything more than I've posted. Thanks, Tim On Nov 24, 8:52 pm, Karen Tracey <kmtra...@gmail.c

Re: Configure multi-field multi-select form in Django Admin

2009-11-24 Thread Tim Valenta
> The javascript will be found somewhere under django/contrib/admin/media/js. To be clear, rc, although the javascript is of course available for viewing, you should only need to put that attribute "filter_horizontal" on your ModelAdmin. There shouldn't be any need for inserting any custom

Re: calendar.js can't find variable gettext

2009-11-24 Thread Tim Valenta
I'm a little unclear on part of that... does this not work only on certain pages? If it doesn't work at all anywhere, I'm not sure where you got the HTML for a working page. Are you sure that all of those URLs resolve to the right JS files? If you go to the page which messes up, and view the

Re: settings.py seems to be cached or stuck

2009-11-24 Thread Tim Valenta
Are you using the development server? There's definitely caching funny-business in a production web server, but that should affect you if you're using "manage.py runserver" Does stopping and starting the development server change anything? Tim On Nov 24, 6:54 pm, Tom

Re: Accessing model instance on pre_save signal

2009-11-24 Thread Tim Valenta
I think the answer is just in the documentation on the method: http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_save No worries though. Signals are such a strangely uncovered topic in the main tutorials, and aren't easy to find documentation for unless you know

Re: creating a drop down filter in Admin site

2009-11-24 Thread Tim Valenta
Not to my knowledge. Condensing them into drop-downs could be an option, though. That might make an interesting patch. I'm not familiar with that part of the code, but it would honestly be more of a template tweak than much code. I'm busy with several projects for the time being, but it would

Re: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
ject list. (I'm using contrib.gis which has nifty map widgets and > it "just works" in the admin but now I'm building my own UI). > > In fact, I'm pretty fuzzy in general about how code like widgets > gets "found" and loaded. > > -Todd Blanchard > > > On

Re: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
bout how code like widgets > gets "found" and loaded. > > -Todd Blanchard > > > On Nov 24, 2009, at 3:52 PM, Tim Valenta wrote: > >> Sorry-- I got out of sync with the replies. >> >>> Or am I missing something. Seems like I am getting very much NON- >

Re: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
blanch...@mac.com> wrote: > No no no, I really really appreciate the help. > > But I'm definitely beginning to feel like my app is 80% boilerplate. > > On Nov 24, 2009, at 3:35 PM, Tim Valenta wrote: > > > > > PS -- I hope I don't sound like I'm insulting your intell

Re: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
present a zillion confusing parts > > to the programmer and it has too many mechanisms but no policies. > > > I'm beginning to very much pine for rails.  At least it does something out > > of the box. > > > Very frustrated today - still haven't got a single rec

Re: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
rustrated today - still haven't got a single record/entry form working. >  Too many little files and indirection to keep it all straight in my head. > > -Todd Blanchard > > On Nov 24, 2009, at 2:05 PM, Tim Valenta wrote: > > > > > The idea is along the lines of what

Re: Module ho.pis can not be found when running on apache

2009-11-24 Thread Tim Valenta
I was caught by surprise when I moved my stuff to a production server, too. The live pythonpath is clearly different than you're expecting, which I'm sure you know already. My ultimate problem was that I was taking advantage of the fact that Django's development server puts your project on the

Re: How to unregister model?

2009-11-24 Thread Tim Valenta
I'm afraid there won't be a core update right away, and it sounds like you're in need of one. Unless someone more knowledgeable with the Database layer can help out, I'm unsure of what else you might be able to do. On Nov 24, 3:02 pm, Tomasz Zieliński <tomasz.zielin...@pyconsultant.eu>

Re: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
The idea is along the lines of what you initially guessed. The admin accomplishes the non-duplicate effect in django/django/ contrib/admin/options.py, starting at line 770. It loops over the forms and combines the existing media with the media on each form object. It ends up using a series of

reversing URLs

2009-11-24 Thread Tim Valenta
Ever since day one, I've never had a firm grasp on what the heck URL reversing can do. I understand the concepts involved, even the admin namespacing that can occur with different admin sites, and I know that the admin uses it regularly, but it seems like a crazy unpredictable wildcard when I try

Re: How to unregister model?

2009-11-24 Thread Tim Valenta
. Tim On Nov 24, 2:18 pm, Tomasz Zieliński <tomasz.zielin...@pyconsultant.eu> wrote: > On 24 Lis, 22:15, Tim Valenta <tonightslasts...@gmail.com> wrote: > > > If you're not doing anything fancy with AdminSite objects (ie, you're > > only using the default admin s

Re: newbie questions regarding models and admin

2009-11-24 Thread Tim Valenta
Your first question about how to separate fields is not perfectly clear to me. However, I can say that I typically put *all* fields on the actual admin objects, since an admin is typically not the one you're trying to restrict. Then, in your own custom views (and the forms you render in those

Re: Django-1.1.1 builtin Development WebServer crashes with a core dump

2009-11-24 Thread Tim Valenta
It's not very clear what is happening. If you start a brand new project, there won't be any URLs for you to visit yet. It will most probably give you the error page, telling you that there is no URL matching the query. A better copy-and-paste would be what the browser is displaying. I hope

Re: How to unregister model?

2009-11-24 Thread Tim Valenta
s once you figure out how to use it. Here's the docs on it: http://docs.djangoproject.com/en/dev/topics/db/models/#id6 On Nov 24, 2:15 pm, Tim Valenta <tonightslasts...@gmail.com> wrote: > If you're not doing anything fancy with AdminSite objects (ie, you're > only using the defaul

Re: How to unregister model?

2009-11-24 Thread Tim Valenta
If you're not doing anything fancy with AdminSite objects (ie, you're only using the default admin site), then do this: # assuming you've already done: from django.contrib import admin admin.site.unregister(MyModel) Note that it's exactly the opposite of the normal "admin.site.register ()"

Re: Forms ModelMultipleChoiceField with checkboxes?

2009-11-23 Thread Tim Valenta
Actually-- quick followup: The widget looks alright if you haven't got the 'aligned' css class on the fieldset. But if you do, watch out :P On Nov 23, 4:20 pm, Tim Valenta <tonightslasts...@gmail.com> wrote: > That widget doesn't seem to look right on *any* browser.  It's got > thi

Re: Forms ModelMultipleChoiceField with checkboxes?

2009-11-23 Thread Tim Valenta
That widget doesn't seem to look right on *any* browser. It's got this weird step-like appearance. Firefox is the only browser where it appears even close to acceptable. I might be submitting a patch for the CSS soon... It's horrible. On Nov 23, 1:14 pm, aa56280 wrote: >

Re: Autocomplete for Generic Foreign Keys

2009-11-23 Thread Tim Valenta
What's the context, exactly? When used as an inline, the Generic- family isn't any different than a normal inline. I'm not sure why you specify that you're looking for a solution for *Generic* foreign keys. If you register a generic model directly to the admin, it gets kind of kooky, so is that

Re: Definitive solution for foreignkey filtering in Admin

2009-11-05 Thread Tim Valenta
the model instance itself. Tim On Nov 5, 4:37 pm, Tim Valenta <tonightslasts...@gmail.com> wrote: > I don't know what changed, but updating my SVN in the last week > sometime has fixed the problem that I was having. > > The dev trunk and I have a love-hate relationship :) >

Re: Definitive solution for foreignkey filtering in Admin

2009-11-05 Thread Tim Valenta
I don't know what changed, but updating my SVN in the last week sometime has fixed the problem that I was having. The dev trunk and I have a love-hate relationship :) I would make a note to anybody reading this that if the 'add' view is being used, you should kick off the code block with a "if

Re: Definitive solution for foreignkey filtering in Admin

2009-10-26 Thread Tim Valenta
y more pointers would be great. Other than this speedbump, I think this will do nicely. Tim On Oct 26, 8:53 am, Tim Valenta <tonightslasts...@gmail.com> wrote: > Many many thanks for the response. > > I had tried that approach, but had no idea what was coming through in > kwar

Re: Definitive solution for foreignkey filtering in Admin

2009-10-26 Thread Tim Valenta
to have a simpler fix to write off in the docs. Tim On Oct 25, 8:28 pm, Matt Schinckel <matt.schinc...@gmail.com> wrote: > On Oct 24, 5:14 am, Tim Valenta <tonightslasts...@gmail.com> wrote: > > > I've been searching for a while on how to intercept querysets in > > f

Re: Need Help Migrating to Windows 7 (64-bit), Python 2.6, Django 1.1

2009-10-24 Thread Tim Valenta
I would still raise the warning of caution, that certain external Python libraries do not have 64-bit versions, like PIL. I tried the whole 64-bit Python thing, and I just couldn't do it because of some library dependancies. I also use a setup like yours on Windows 7, except with MySQL, and a

SQL syntax error in Admin

2009-10-24 Thread Tim Valenta
If there's nothing I can determine here, I'll move over to submitting a ticket on the matter. Wanted to check in here first. Using... Django 1.2 SVN revision 11653, (updated just 2 minutes ago) MySQL 5.1.31 Models: class Category(models.Model): category = models.CharField() class

Definitive solution for foreignkey filtering in Admin

2009-10-23 Thread Tim Valenta
I've been searching for a while on how to intercept querysets in forms, to apply a custom filter to the choices on both foreignkey and m2m widgets. I'm surprised at how there are so many similar questions out there, dating back to 2006. I came across the documentation for

Re: Limit choices based on a foreign key

2009-10-22 Thread Tim Valenta
I would very much be interested in a solution to this problem. I can't yet understand why Django is so wonderful at so many things, yet has absolutely no mechanism for this. Every time there seems to be hope of a working solution, it never works for inlines. For the sake of painting up another

Re: m2m trouble when referencing "self"

2009-04-26 Thread Tim Valenta
Amazing, thanks. I just couldn't find the documentation to prove it one way or the other. I just didn't guess that anything would be different by default! Much appreciated, Tim On Apr 25, 4:28 pm, Alex Gaynor <alex.gay...@gmail.com> wrote: > On Sat, Apr 25, 2009 at 6:26 PM, Ti

m2m trouble when referencing "self"

2009-04-25 Thread Tim Valenta
Hello all. I tried the IRC, but it's too chaotic and not enough people take you seriously :) Very very abbreviated example code: class Person(models.Model): parents = models.ManyToManyField('self', related_name='children') Now, the exact relationship is just an example, but it

django searching wrong package for 'static.serve'

2009-01-17 Thread Tim Valenta
Hello all. Just trying to make django serve my static media files (css is my main test case right now) during development. I've included the lines in my URLconf as instructed by this page: http://docs.djangoproject.com/en/dev/howto/static-files/ My issue is that this line is causing a 500