Re: Hierarchical data containing different models

2010-02-25 Thread Marco Rogers
Couple of things. bruno, your save example should maybe look call the superclass save first. Otherwise parent may not have been set yet.     def save(self, *args, **kw):         super(Node, self).save(*args, **kw)         if self.parent and type(self.parent) != Group:             raise

Re: apparent bug in QuerySet

2010-02-22 Thread Marco Rogers
This is interesting. I think the two examples you give are distinct use cases and they should be. But I think it's just as common to want to do what felix is doing. Essentially he wants to modify a queryset as it exists by adding or overriding additional parameters. It can be very convenient

Re: Downloadable CSV file of Survey?

2010-02-18 Thread Marco Rogers
Definitely use python csv and do it yourself. It's really very simple. shaner's links above should help. One thing I would add is make sure you convert all of your model values to unicode because otherwise the csv module will choke on bad characters. unicode(value, 'utf8') :Marco On Feb

Re: about sending email

2010-02-17 Thread Marco Rogers
Check out this solution for testing emails when in development. It allows you to use send_mail and the email output is printed to the terminal (the one running the runserver process). http://jboxer.com/2009/05/non-painful-email-on-django-development-servers/ When you're ready to go live, you'll

Re: Save inline instances first

2010-01-18 Thread Marco Rogers
I had a need for this at one point because my main model had an overridden save method that would modify the inlines. But it didn't work because the inlines weren't there. I had to reverse the save method and put it on the inline model. But in my case, there was no reason not to do that. :Marco

Re: Problem when trying to validate a field in a ModelAdmin which has inline forms

2010-01-15 Thread Marco Rogers
I've never had to do this but it sounds you want to work with Form.clean() in stead of Form.clean_is_approved(). From the docs: "The Form subclass’s clean() method. This method can perform any validation that requires access to multiple fields from the form at once." So in your clean method

Re: list_display functionality for inlines ?

2010-01-12 Thread Marco Rogers
I'm trying to find a solution to this very same issue. At the very least, I think inlines should support custom callables. The inline I'm displaying is an intermediary table for a ManyToMany relationship. So I have a selector for the related object, but what I would like to do in the inline is

Re: How to get ModelAdmin given a Model

2010-01-12 Thread Marco Rogers
t;tomasz.zielin...@pyconsultant.eu> wrote: > > On 11 Sty, 16:23, Marco Rogers <marco.rog...@gmail.com> wrote: > > > > I'm reposting this from earlier to see if I have better luck. I need > > > to be able to get the ModelAdmin associated with a model at runtime.

How to get ModelAdmin given a Model

2010-01-11 Thread Marco Rogers
I'm reposting this from earlier to see if I have better luck. I need to be able to get the ModelAdmin associated with a model at runtime. Similar to how django.db.models.get_model allows you to retrieve a model. admin_class = get_admin(Model) Is this possible? The original post has more

Re: Passing a parameter into a queryset for a generic view

2010-01-07 Thread Marco Rogers
I was looking for some convenient method like this to use with the object_list generic view. But writing my own wrapper view only took 2 secs. def speaker_list(request, session_month): if not session_month in settings.SESSIONS: return HttpResponseNotFound()

How can I retrieve the ModelAdmin given the model class or an instance?

2010-01-06 Thread Marco Rogers
I'm retrieving a model using django.db.models.get_model. The view is receiving a post from a form generated by the ModelAdmin. How can I get a hold of that ModelAdmin instance so can then get a hold of the ModelForm? This will allow me to process the post (validation, related objects, etc).