Sphinx code validation for Django projects

2012-10-17 Thread Martin Winkler
 I have a Django project with a couple of apps - all of them with 100% 
coverage unit tests. Recently I started documenting the whole thing in a 
new directory called "docs" using reST and Sphinx. I create the html files 
using the normal approach: make html. 

Since there are a couple of code snippets in these reST files, I want to 
make sure that these snippets stay valid over time as the project evolves. 
I looked up the git repo for docs.djangoproject.com, but did not find this 
functionality there.

So what is a good way to test the code snippets inside these reST files, so 
I get an error if some API changes made such a snippet invalid? I guess 
there have to be some changes in conf.py?

Martin

-- 
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/-/gfegCVn4KjcJ.
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.



Forms with dynamic *fields*

2009-03-02 Thread Martin Winkler

Hi all,

I want to create a form with dynamic fields. That is, I want to add the
fields using the __init__ method of my form:

1   class MyForm(forms.Form):
2   def __init__(self, fieldnames=(), *args, **kw):
3   for fieldname in fieldnames:
4   self.XXXfieldnameXXX = forms.CharField(...)
5   super(MyForm, self).__init__(*args, **kw)

What is the correct syntax for line 4? Is this even possible?

Martin

--~--~-~--~~~---~--~~
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: ImageField upload_to Parameter Problem

2007-07-04 Thread Martin Winkler

Am Wed, 04 Jul 2007 01:19:16 -0700
schrieb lastmohican <[EMAIL PROTECTED]>:

> The Problem is, I want a dynamic image
> storage path, something like MEDIA_ROOT+"images/" wont work with
> hundreds of galleries, [...]

Since your primary concern seems to be too many files in one directory,
did you check
http://www.djangoproject.com/documentation/model-api/#filefield
especially the paragraph about "%Y/%m/%d" ?

So you could do this:

image = models.ImageField(upload_to='images/%Y/%m/%d')

Of course the images of one album are not in one directory, but this
solution still makes more sense:
1) Many users might not upload any images at all - so there would be
many empty directories.
2) Some users might upload a whole lot of images - your problem with too
many files in one directory will come up again.

An additional benefit: If you run out of diskspace, you could mount a
different volume under $MEDIA_ROOT/images/2008 for the next year.

And of course django will always know where your images are:

[ i.image for i in Gallery.get(slug="foobar").image_set.all() ]

will get you all images for one gallery.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MySQL Got packet bigger than 'max_allowed_packet'

2007-07-03 Thread Martin Winkler

Am Tue, 3 Jul 2007 17:34:33 +0200
schrieb Martin Winkler <[EMAIL PROTECTED]>:

> If you have binary data, why don't you use FileField and ImageField?
> That way you'd store the large data in the filesystem and only have a
> reference to the file in the database.

Maybe I should clarify the problems as far as I am aware of them:

Whenever you work with the result of MyModel.objects.filter()
or .all() or even .get(), django loads the complete record(s) including
all fields into memory. So if you want to present just a list of titles
of 20 of your records, all these 20 records will be loaded into memory -
which might be a HUGE amount of data. (As long as you don't play around
with specialized Q() objects, as far as I know)

Furthermore Django is not really meant to serve huge amounts of (more
or less) static data. That's what your webserver is for. Your webserver
might be able to continue a download which stopped in the middle at
the correct location etc.

So for me it makes much more sense to store the binary data in the
filesystem because it has much less overhead. The only disadvantage I
can see here is that for backups you not only have to save your
database, but also one directory (including subdirs) of your file
system.

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MySQL Got packet bigger than 'max_allowed_packet'

2007-07-03 Thread Martin Winkler

Am Tue, 03 Jul 2007 15:07:14 -
schrieb "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>:

> We are using mysql 5.0.42 and are getting this error when trying to
> insert records of over 5M.

I may sound nosy, and apologize for that. But don't you think that you
have a software design bug when one record in a table exceeds 5 MB?

If you have binary data, why don't you use FileField and ImageField?
That way you'd store the large data in the filesystem and only have a
reference to the file in the database.

Just my 2 eurocent

Martin



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Graphs and django

2007-06-20 Thread Martin Winkler

Am Wed, 20 Jun 2007 16:26:24 +0100
schrieb "Gerry Steele" <[EMAIL PROTECTED]>:

> My needs are to create line, bar and pie charts.

One fast way for line graphs would be plain PIL
(http://www.pythonware.com/products/pil/) module. But the results are
usually not really pretty: No antialiasing of lines, except you also use
the aggdraw module (http://effbot.org/zone/aggdraw-index.htm).

If you want do do really nice graphs, you might take a look at some
screenshots of matplotlib:
http://matplotlib.sourceforge.net/screenshots.html

The module is quite large, but has really many functions: from simple
pie charts (3D too) up to finance charts which gets data from
finance.yahoo.com

I took quite some time until I figured how matplotlib/pylab works, but
eventually I succeeded. Hopefully you'll get to some good results
faster than me :)

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Survey: FileBrowser and FancyUpload

2007-06-16 Thread Martin Winkler

Hi Patrick,

Am Sat, 16 Jun 2007 12:47:46 +0200
schrieb patrickk <[EMAIL PROTECTED]>:

> 
> I usually don´t like the idea of using a js-framework for the  
> filebrowser.
> nevertheless, today I´ve seen this:
> http://digitarald.de/project/fancyupload/

I tried it too, and just after finishing the upload of my two images
Firefox crashed. Maybe the tool is not that stable as I wish.

Furthermore I like the filebrowser as it is right now - without any
flash plugins. So I'm personally at a strong -1 with this.

Maybe it would be better to check out how gmail does attachment
uploads, because in my opinion this is a very nice solution: After
choosing a file to upload, a new "Browse" button appears.

For me that would really be enough - please can you leave your current
behaviour at least as a fallback solution?

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Generic Views: "Could not parse the remainder: % object.title %"

2007-06-15 Thread Martin Winkler

Am Thu, 14 Jun 2007 14:53:42 -0700
schrieb "Evan H. Carmi" <[EMAIL PROTECTED]>:
>  {{% object.title %}} 
>  {{% object.body %}} 

this is a syntax error and should be:
 {{ object.title }} 
 {{ object.body }} 

They are variables, and not tags.

just check http://djangoproject.com/documentation/templates/#variables

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Captcha module Version 1.1 ready for testing

2007-06-15 Thread Martin Winkler

Am Fri, 15 Jun 2007 14:53:59 +0800
schrieb "Nimrod A. Abing" <[EMAIL PROTECTED]>:

> I will be downloading your module and testing it out soon. 

Cool! I'd love to get some feedback especially with different setup
than I have.

> If I have patches for your module, do I send it here on django-users
> or can I send to you directly?

For patches it's better if you send them to me directly for the time
being. (Attachments on django-users are not a good idea, as far as I
know)
And maybe the module will be good enough for the django developers to
put into trunk soon? (can someone of the core developers inform me how
the chances are?)

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Captcha module Version 1.1 ready for testing

2007-06-15 Thread Martin Winkler

Am Thu, 14 Jun 2007 15:51:10 -0400
schrieb Forest Bond <[EMAIL PROTECTED]>:

> You can do it without external persistence (sessions and/or database
> table) by encrypting the correct response in the image filename.

So when the request to get the image is sent to django, we have to
decrypt the solution according to the image's URL. In my
opinion that raises some problems, because it could be decrypted by
someone else too, unless you use a private/public key encryption,
which means more work on the django server than using just hashed
filenames like my approach does.

Furthermore I don't see a real reason to generate images on the
fly instead of storing them directly. My approach is quite speedy even
with auto_cleanup, when there are many captcha images sitting in the
filesystem all the time. I ran an apache benchmark test on my
development machine (not the fastest hardware) multiple times where
each of them creating 1000 captchas:

With auto_cleanup:
captchas on disk at startRequests per second
first run   0  22.82
second run   1000  13.06
third run2000   9.16
fourth run   3000   7.02

Without auto_cleanup:
captchas on disk at startRequests per second
first run   0  39.05
second run   1000  39.45
third run2000  37.27
fourth run   3000  38.46

disk space used for 4000 captchas: 48MB

And these are really extreme cases, since they imply that no one of the
1000 visitors in each run ever submits a form back, so its captcha image
would be deleted automatically.

If you really have concerns regarding speed, you might use a cronjob
that deletes the old captchas in the background, so the whole system
stays very responsive.

If you have a compelling reason why this solution is bad, I'll be happy
to know. Otherwise I think, I'll stick with images in the filesystem.
In my opinion it's fast for most sites even with auto_cleanup, and for
really high volume sites just disable auto_cleanup, use your own
cronjob, and everything should be ok. Right now, I just can't see a
benefit in using images created on the fly.

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Captcha module Version 1.1 ready for testing

2007-06-14 Thread Martin Winkler

Am Thu, 14 Jun 2007 12:00:11 +0800
schrieb "Nimrod A. Abing" <[EMAIL PROTECTED]>:

> Are you planning to implement a configuration to allow in-memory
> images?

One thing that annoys me with in-memory images is that you have to
change your urls.py, and I want the CaptchaField as unobtrusive as
possible. Furthermore this method needs some kind of session data
stored somewhere, and therefore also cookies. All this annoys me a bit,
to be honest.

> Characters that can confuse users have been removed from this set. But
> some fonts are more legible than others, so it should be possible to
> configure the characters to use. Are considering implementing this?

Good idea! Although I already have used an incomplete alphabet for
this, it seems natural that developers want to use their own "alphabet"
- which might be only digits, and no characters.
So I made a nice configuration possibility for my captcha module. You
can define it in your settings.py, and also adjust individual forms, if
you wish.

> 3. No "twists" are applied to characters. I have found that distorting
> characters tends to confuse users even more. Will there be a
> configuration that will disable "twists"?

Yes. You can specify rotation, sizes, vertical positions and other
values according to your needs. The only thing that is not so elegant
is: all characters are aligned on top. That means that a lowercase
character might look as if it is superscript. If you only use uppercase
and numbers, then this is no problem.
(BTW: The user can enter only lowercase characters - the captcha test
is also successful, even if the image also shows uppercase characters)

> I really hope your module gets included in contrib since I really like
> the "one standard way" for doing things approach.

Me too!

There is a significantly updated version available now:
 http://django.agami.at/captchatest/  - with download, docs and demo
 ("reload" the page, if you have already been there...)

 * The old version had a bug in not removing outdated captchas. FIXED
 * new configuration options
 * save as gif image with adaptive color palette to minimize filespace.
   if it*s not possible to save as gif, it falls back to jpg. 
   (I had a problem on FreeBSD with gif images)
 * there is now an "iterations" option - which writes many captchas
   over each other for testing purposes. (so you can adjust width and
   height of your captcha according to your font settings)

Hope you like it,

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Captcha module ready for testing

2007-06-13 Thread Martin Winkler

Am Wed, 13 Jun 2007 18:47:10 -
schrieb JustJohnny <[EMAIL PROTECTED]>:

> I just installed your captcha module. I'm not sure if it was me, my
> setup or the code but I kept getting a 'help_text' error.

That is very strange - help_text is part of django's newforms fields. I
tried to reproduce your error, but I was not able to see this error.
Maybe you have an older version of django? I am using captcha with a
pretty recent checkout of the trunk. (revision 5443)

> After I got past that, I discovered that I needed to install FreeType2
> and then had to reinstall PIL to pick up that change.

Right. you need this for truetype fonts. and also PIL version 1.1.6
(which is out since December 2006.

Glad you like the module.
Maybe you can give me more information about your error? Which django
version, which OS? I only have tested it on Fedora Core 6 and FreeBSD
6.0 with a manual install of PIL 1.1.6, so there might still be some
issues with the code.

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bug in django related to sqlite3?

2007-05-14 Thread Martin Winkler

Hi Francesco,

Am Mon, 14 May 2007 12:44:46 -
schrieb cesco <[EMAIL PROTECTED]>:

> query = """SELECT id FROM my_table \
> WHERE my_table.some_id IN %s"""
> cursor.execute(query, [(1, 2, 3)])

why are you diving so deep?
can't you just use

myobjects = MyTable.objects.filter(some__in=(1,2,3)) ?

(I am assuming that your model is called MyTable and that the field
"some_id" is in fact a ForeignKey field called "some")

If you absolutely _have_to_ use the query/cursor code, then sorry, I
personally don't have a solution for that.

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Transaction Support in Models

2007-05-07 Thread Martin Winkler

> do models support transactions?

Yes, with the TransactionMiddleware. And it's well documented:
http://www.djangoproject.com/documentation/transactions/

> can we have multiple orders in our models(getting /fetching) records
> from our backend DB?

Sure. default ordering is defined in the model metadata
( http://www.djangoproject.com/documentation/model-api/#meta-options )
and you can use any other ordering anytime in your (generic) views:
Entry.objects.filter(foo='bar').order_by(['-date_published','headline'])

> can we use stored procedures (sp) through  our models?

Django does not support stored procedures (yet). But you can at least
use the lower-level db-apis of cxOracle or psycopg2.

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Primary ForeignKey create try

2007-05-05 Thread Martin Winkler

Am Sat, 05 May 2007 10:22:14 -0700
schrieb Heit <[EMAIL PROTECTED]>:

> TYPE_CHOICES = (('user', 'USER'),('serve',  'SERVE'))
> class Person(models.Model):
> ...
> type = models.CharField(maxlength=30, unique=True,choices=
>TYPE_CHOICES, default='user')
> ...

So you can have at most 2 records in Person table (because of
unique=True). One with type="user" and one with type="serve". Is this
*really* what you want?

> I changed some code in django.contrinb.admin.views.main and now it
> works fine for me.

Do not - I repeat: DO NOT - change code in contrib.admin.views. It is
almost NEVER a good idea... :)

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Deos Django have Java Servlet's Listener like thing?

2007-05-05 Thread Martin Winkler

Am Fri, 04 May 2007 21:06:52 -0700
schrieb Mambaragi <[EMAIL PROTECTED]>:

> Is there anything like Servlet Listener in django,python?

not easily if you use mod_python, because for every apache thread a new
python instance is being generated.

but it should be easy using fastcgi, since it uses a
single python instance to which apache connects.
see http://www.djangoproject.com/documentation/fastcgi/

just out of curiosity: what are your design-specific reasons for such a
thread?

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Accessibility

2007-05-04 Thread Martin Winkler

Hi Allessandro, 

> Is Django framework ready to get Web Content Accessibility Guidelines
> - v 1.0 (WCAG 1.0) of WAI, and Section 508 paragraph 1194.22 of
> Rehabilitation Act?
> 
> I need to make a website that is conform to those specs, and I need
> to know If the admin section and newforms are already up to them.

admin section: should be ok - except for M2M relationships - at least in
auth.User edit-screen, because the group-area is dependent on
JavaScript. As far as I know, everything has to work without javascript
to conform to the specs, but I could be wrong, since I do not have a
link to the specs at hand.

The newforms and any other thing has nothing to do whether it's WAI
compliant or not. That is up to you!

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Page Not Found 404

2007-03-06 Thread Martin Winkler

Am Tue, 06 Mar 2007 15:29:06 -
schrieb "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>:

> I am making simple blog for myself using Django. After made models and
> create necessary urls, I run the application and got: Page Not Found.
> [...]
> >>> from mysite.blog.models import Post
> >>> Post.objects.all()
> []

It is necessary that you provide MUCH more information to us...

At least the following:

 * The relevant parts of your urls.py (generic views, yes?)
 * The template source code

Maybe then it is possible to see the reason of the error.

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: applying a patch in windows ???

2007-03-06 Thread Martin Winkler

Am Tue, 6 Mar 2007 17:37:21 +0530
schrieb "MacH G" <[EMAIL PROTECTED]>:

> i do [not] know how to apply
> it in windows could somebody tell me the command to apply it .

If you are comfortable with the unix command line, install cygwin
(http://www.cygwin.com/). You'll get a full unix shell environment
including the gnu diff tool.

Otherwise you might have a look at the various diff/merge tools
available for Windows.
For example:
http://www.thefreecountry.com/programming/filecomparison.shtml
or use your favourite search engine with the keywords "windows diff
tool"

As a last resort, edit the files manually as seen on
http://code.djangoproject.com/attachment/ticket/3400/list_filter.3.diff
Remove red lines, insert green lines.

hope that helps,

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: newforms: comparing fields during validation

2007-03-06 Thread Martin Winkler

Hi "ezln23",

> I am using the newforms functionality, but I am having trouble
> validating my form when two fields are needed to create the validation
> rule.

try this:

class CreateAccountForm(forms.Form):
   name = forms.CharField(max_length=50)
   name_phonetic = forms.CharField(max_length=50)
   email = forms.EmailField()
   password_1 = forms.CharField(max_length=20)
   password_2 = forms.CharField(max_length=20)
   homepage = forms.URLField(verify_exists=True)

   def clean_password_2(self):
   get = self.clean_data.get
   if not (get('password_1') or get('password_2'):
   raise forms.ValidationError(u'Please enter a password')
   if (get('password_1') or get('password_2')) and \
   (get('password_1') != get('password_2')):
   raise forms.ValidationError( \
u'You did not enter the same password twice.')
   return self.clean_data['password_2']

The error will be bound to field "password_2" in this case.

You can also have a look at the file
django/tests/regressiontests/forms/tests.py
and search for "Validating multiple fields in relation to another"

hope that helps.

Martin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: creating custom "filter_*" methods for objects

2007-02-11 Thread Martin Winkler

Am 11 Feb 2007 04:07:03 -0800 schrieb "[EMAIL PROTECTED]"
> 
> On 11 Lut, 12:32, Martin Winkler <[EMAIL PROTECTED]> wrote:
> > One (quite non-elegant) way would be adding a method to the class
> > Manager in django.db.models.manager like this:
> >
> > def filter_active(self, *args, **kwargs):
> > kwargs['is_active'] = kwargs.get('is_active', True)
> > return self.get_query_set().filter(*args, **kwargs)
> >
> > But that would mean changing django core files, which I really do
> > not like. I'd much prefer adding a method to my own model - but how?
> 
> Create your own manager: subclass models.Manager, add your
> filter_active
> method there and tell your models to use the new manager as .objects.
> 
> See http://www.djangoproject.com/documentation/model_api/#custom-
> managers

Thank you for showing me an interesting part of the documentation!

The following chapter (modifying-initial-manager-querysets) led me to
the solution of my problem! So by calling
MyModel.active_objects.filter(title__contains='D') I can use anything I
want, and I am still able to use the normal "objects" class for the
admin interface.

The syntax is a bit different than I expected, but it is also more
elegant than my previous approach :)

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



creating custom "filter_*" methods for objects

2007-02-11 Thread Martin Winkler

Hi all,

many of my models have a boolean field "is_active".

Now I'd like to implement a convenience method that automatically uses
this field when accessing my models.

What is the best way to implement something like
MyModel.objects.filter_active()?

One (quite non-elegant) way would be adding a method to the class
Manager in django.db.models.manager like this:

def filter_active(self, *args, **kwargs):
kwargs['is_active'] = kwargs.get('is_active', True)
return self.get_query_set().filter(*args, **kwargs)

But that would mean changing django core files, which I really do not
like. I'd much prefer adding a method to my own model - but how?

Hoping for some clues...

Martin


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Detection of "tainted" fields

2007-01-16 Thread Martin Winkler


Hi all,

I need to check if a certain field in my model has changed before
saving:

--
model MyModel(models.Model):
   mypic = models.ImageField()
   def save(self):
   if self.mypic.tainted:
   # do some work because the image has changed
   super(MyModel, self).save()
--

So I only would need some advice on this "tainted" thing :)
Any thoughts on what I could use to solve my problem?

BTW: It has to be in the "save" method, because I need to work on the
image even when a staff member uploads something from the admin
interface.

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: What IDE do you use? (semi-OT)

2006-10-08 Thread Martin Winkler

> I'd like to know what editor/IDE Django users (and developers) uses on
> daily basis,

I love Vim (Linux and if necessary Windows) since about 4 years.
Main reasons:

* super fast because of the sophisticated motion keys and
  multi-line editing (visualmode I)

* filetype plugins for django-html and of course python

* nice folding of python code

* Iabbr  {% <> %}andIabbr  {{ <> }}
  for quickly inserting django blocks/tags into templates

* I could go on endlessly...

The bad thing with vim is a relatively steep learning curve
at the beginning, but after a short while I began to love this editor
for its many features and external plugins. ("dbext" for database access
inside the editor, and "vtreeexplorer" for a nice vertical hierarchical
file selector, "taglist", "pydoc", ...)

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Count clicks

2006-10-07 Thread Martin Winkler

Hi,

> In my model i have an IntegerField called "count". What would be a
> good way to increment the post with post_id=1 when someone 
> accesses "http://www.mysite.com/news/1;? Resp. where do i put my code?

I can see here two issues:
It's generally a bad idea to update anything in the database without a
POST form. (see tutorial 4, "vote()" function)

Second, you do a database-update whenever an anonymous user views a
page - this can be a major performance issue.

Why don't you run a cronjob asynchronously - say: once every hour or
day, that checks your webserver's access log and updates all relevant
numbers in one session?

just my 2eurocents,

Martin

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---