Re: 404 only in Chrome

2011-12-10 Thread Tomasz Zieliński
Can it be a browser caching issue: 
http://www.google.pl/support/forum/p/Chrome/thread?tid=3bb0a94bfb063745=en
 ?

Best,
Tomasz Zielinski

-- 
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/-/YXHy-SR-m0cJ.
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: Mysql + Unicode + username curiosity

2011-11-14 Thread Tomasz Zieliński
You might want to check the documention: 
https://docs.djangoproject.com/en/1.3/ref/databases/#creating-your-database

There seem to be issues like this one: "The main thing to be aware of in 
this case is that if you are using MySQLdb 1.2.2, the database backend in 
Django will then return bytestrings (instead of unicode strings) for any 
character fields it receive from the database." so it's possible that you 
also suffer from some configuration problem.


-- 
Tomasz Zielinski

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



Odp: Reasons to use managers

2011-06-04 Thread Tomasz Zieliński
If you use manager method, you can keep your schema unchanged/normalized 
and employ e.g. Memcached or Redis to store the result of your computation.
This might or might not fits your use case, of course.

--
Tomasz Zielinski
pyconsultant.eu

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



Odp: Re: Problem uploading images and videos with filenames containing not ascii characters

2011-05-03 Thread Tomasz Zieliński
W dniu wtorek, 3 maja 2011, 21:34:28 UTC+2 użytkownik Ariel napisał:
>
> Yes, only on the production enviroment.
>
>
>  
Try to create a file with UTF8 characters in its name, from your code. 
Then you'll know if those Apache settings are in effect.

-- 
Tomasz Zielinski
pyconsultant.eu

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



Odp: UnicodeDecodeError with makemessages in django-1.3

2011-05-02 Thread Tomasz Zieliński
I got the same exception, it turned out that our designer put some invalid 
characters into one of the templates.
I figured out which template had been broken, due to the fact that 
`makemessages` left empty `buggy_template.html.py`
 file in `buggy_template.html` folder.

-- 
Tomasz Zielinski
pyconsultant.eu

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



Session "rollback" after transaction rollback

2011-03-29 Thread Tomasz Zieliński
How do you handle situation in which exception is raised from view,
TransactionMiddleware rolls back the open transaction, but subsequently 
SessionMiddleware updates session in database with broken data
(i.e. something that points to what was rolled back 
by TransactionMiddleware) ?

This is an edge case but quite interesting one, at least for me.

-- 
Tomasz Zielinski
pyconsultant.eu

-- 
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: ManyToMany Intermediate Table on a Separate Database?

2011-03-29 Thread Tomasz Zieliński
(Sorry Daniel, I replied to your private email by accident - the new Google 
Groups UI misled me.)

Actually in MySQL you can easily work around that limitation 
- you can use database VIEWs as mirrors of tables placed in other databases.

-- 
Tomasz Zielinski
pyconsultant.eu

-- 
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: Logging visitors/requests and showing it all in a nice report?

2011-03-22 Thread Tomasz Zieliński
On 21 Mar, 14:21, Thomas Weholt  wrote:
> Is there an app for logging visitors with a nice report, like a report
> showing number of visitors for a specific page, users with a specific
> browser/OS etc?
>

I know you want a Djangoish solution, but there is a nice small
Apache log analyzer http://www.hping.org/visitors/ which output
might fit your purposes.

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: orm: operations between models fields

2011-03-21 Thread Tomasz Zieliński
On 19 Mar, 22:49, maxi  wrote:
> Hi,
>
> Which is the better way to do this on orm language ?
>
> select filed1, sum(field2 * field3)
> from a_table
> group by field1
>

I believe this is not possible in the current Django ORM.
It would need something like this to work:

   MyModel.objects.annotate(mult_result=F('field2') *
F('field3')).values('field1').annotate(sum_result=Sum('mult_result'))

- which I find much more ugly than the raw SQL.

Also, you doesn't seem to need to get database rows (objects), just
some custom statistics, and ORM stands for Object-Relational Mapper,
which also makes the SQL way perfectly justified.

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: How to delete ONLY m2m relation?

2011-03-10 Thread Tomasz Zieliński
On 9 Mar, 16:12, Casey Greene  wrote:
> In that case, I believe you can remove it with
>
> user.province_set.remove(province)
> user.save()
>

User.save() is unnecessary here because remove() changes m2m
intermediate table
and save() changes only User table.

>
> I am going from memory here.  I tried to find this in the docs to make
> sure but couldn't.
>

Here you are: 
http://docs.djangoproject.com/en/1.2/ref/models/relations/#django.db.models.fields.related.RelatedManager.remove

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: Tracking Model's History

2011-03-10 Thread Tomasz Zieliński


On 7 Mar, 05:06, Venkatraman S  wrote:
> Hi,
>
> Similar to the way, the admin tracks the changes, i was looking for
> something which can be used in my app and stumbled on
> this
> .
> Q is : How efficient is this? I mean, do you see performance problems in
> your app when you implement this feature?Anything else that needs to be
> taken care of?
> Also, is it possible to know what were the old and new values of the field
> that are getting updated?
>
> -V-http://blizzardzblogs.blogspot.com/

One of the answers there was to use django-reversion - you can try if
it fits your needs.
It stores previous states of the model instance using XML notation,
which makes it possible to migrate models without loosing history.

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: Django 1.2.5 postgres autocommit and contenttype sites tests failures

2011-03-04 Thread Tomasz Zieliński
On 4 Mar, 14:22, David De La Harpe Golden
<david.delaharpe.gol...@ichec.ie> wrote:
> On 04/03/11 10:01, Tomasz Zieliński wrote:
>
> > On 2 Mar, 00:10, Jason Culverhouse <ja...@mischievous.org> wrote:
> >> Hi,
> >> It seems that the contenttype framework and the sites contribs
> >> conflict with using the autocommit:True database option.  
>
> > Do you really need that autocommit? Django has its own concept of
> > autocommit,
> > which seems to just work most of the time.
> > With database-level autocommit turned on, Django-level transaction
> > handling
> > is not going to do anything useful.
>
> Uhm. That's inaccurate in the postgresql case, IIRC.

Ah, you are right! I assumed that it's implemented in a simlar way
across all backends.
MySQL backend doesn't mess with isolation levels and database
autocommit, leaving
default autocommit=False, as Python DB API requires.

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: Configuring Django-Sentry to send error mails

2011-03-04 Thread Tomasz Zieliński


On 4 Mar, 05:49, Ajay  wrote:
> am using django-sentry for logging errors. I also want to enable
> throttled error mails to be sent to admins whenever an error occurs.
> But I can not get it working.
>
> a) Normal django error mailing is working. b) but on removing ADMINS
> and adding SENTRY_ADMINS(like below) it stops working:
>
>    DEBUG = False
> TEMPLATE_DEBUG = DEBUG
>
> SENTRY_TESTING = True
>
> ADMINS = ()
> SENTRY_ADMINS = ('my.n...@domain.com',)
>
> MANAGERS = ADMINS
>
> MIDDLEWARE_CLASSES = (
>         'sentry.client.middleware.SentryResponseErrorIdMiddleware',
> 
> )
>
> EMAIL_USE_TLS = True
> EMAIL_HOST = 'smtp.gmail.com'
> EMAIL_HOST_USER = 'n...@gmail.com'
> EMAIL_HOST_PASSWORD = 'password'
> EMAIL_PORT = 587
>
> Though entries are correctly being made and shown in panel. I mark all
> errors as resolved before testing(to satisfy throttle condition of
> sentry) but it is still not working.
>
> Can anyone point to what I am doing wrong here?

Everything looks ok on the first sight. Do you have sentry and
sentry.client
in your INSTALLED_APPS ? Does console SMTP backend print anything ?

One thing that once bit me was that ADMINS required tuples,
whereas SENTRY_ADMINS was just a plain string list.
But you seem to have this set correctly.


--
Tomasz Zielinski
pyconsultant.eu

-- 
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: Need help with this basic query (annotate vs aggregate)

2011-03-04 Thread Tomasz Zieliński


On 4 Mar, 01:19, Steven Sacks  wrote:
> Here is my model:
>
> class PlaylistTag(models.Model):
>     playlist = models.ForeignKey(Playlist)
>     tag = models.CharField(max_length=128)
>     tag_count = models.PositiveIntegerField(default=1)
>
> The way this model works is simple. If you add a tag to a playlist,
> and the tag doesn't exist, the tag_count is 1. If you add the same tag
> again to that playlist, the tag_count is incremented. If you remove
> that tag, it is decremented. If it reaches 0, I remove the row
> entirely.
>
> A playlist can have multiple tags and a tag can belong to different
> playlists.
>
> (...)
>
> Does this make sense?

IMHO - no, that doesn't make sense :-)

What you need fior the start - and in fact write about - is:

   playlists = ManyToManyField(Playlist)

and no `tag_count` field, unless you want denormalize your schema -
which you probably don't.

To count tags for given playlist, you simply do:

   playlist.playlisttag_set.count()


Last but not least, looking at your SQL query it might be that I don't
quite get what you need.

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: Django 1.2.5 postgres autocommit and contenttype sites tests failures

2011-03-04 Thread Tomasz Zieliński
On 2 Mar, 00:10, Jason Culverhouse  wrote:
> Hi,
> It seems that the contenttype framework and the sites contribs
> conflict with using the autocommit:True database option.  

Do you really need that autocommit? Django has its own concept of
autocommit,
which seems to just work most of the time.
With database-level autocommit turned on, Django-level transaction
handling
is not going to do anything useful.

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: Override default django Registration email

2011-03-04 Thread Tomasz Zieliński


On 3 Mar, 14:23, bruno desthuilliers 
wrote:
> On 3 mar, 13:39, Kenneth Gonsalves  wrote:
>
> > On Thu, 2011-03-03 at 00:36 -0800, pols wrote:
> > > Anyone knows how to override djangos default registration email.I
> > > need to alter it to sent as html email instead of text email.As i am a
> > > bigner of django help me with complete information
>
> > copy the templates to a folder called registration in your project and
> > modify it how you like
>
> If the OP is talking about django-registration, overriding the
> templates will not be enough, as
> RegistrationProfile.send_activation_email sends plain text mails.

Exactly, one need to hack django-registration email sending code
(which is not difficult by the way:
http://docs.djangoproject.com/en/1.2/topics/email/#sending-alternative-content-types).

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: What apps or snippets to use for Facebook and Twitter registration, login and posting?

2011-03-03 Thread Tomasz Zieliński


On 2 Mar, 18:30, Jason Culverhouse  wrote:
> On Mar 2, 2011, at 8:28 AM, Rodrigo Cea wrote:
>
> > I am developing a site that I want to link with Facebook and Twitter.
>
> https://github.com/flashingpumpkin/django-socialregistration(note the forks)
>

Personally I like django-socialregistration, it fits my brain
circuits more than other packages - which of course is a subjective
recommendation.

One thing to note is that JavaScript-based FB Connect is very tricky
to use
if you want to rely your user authentication on it - it's more suited
for sites
where user merely connects tab with the site to tab with FB, to post
some wall posts.

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: How to reduce DB queries?

2011-03-01 Thread Tomasz Zieliński


On 27 Lut, 16:26, galago  wrote:
> In template in main loop I want to display all technologies assigned to the
> each site. Technologies are assigned by m2m relation. So I run subloop as
> You can see in code above. I want to reduce the number of queries executed
> by those subqueries. I want to know, if there is a better way to do this.

Take a look at this add-on: https://github.com/lilspikey/django-batch-select
The example in Readme looks exactly like what you need.

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: django cache (memcache) items are not readable between processes

2011-02-26 Thread Tomasz Zieliński
Looks like you don't really use memcached backend or your memcached
daemon is down.

--
Tomasz Zielinski
pyconsultant.eu

-- 
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: Change language on login

2011-02-21 Thread Tomasz Zieliński


On 21 Lut, 21:50, "Mishen'ka"  wrote:
> Hello all,
>
> I have make a site with translated menu items etc.
> Now i want to change the language on login.
>
> By example i'm from the netherlands and want the Dutch language.
> or i'm from america, so i want English as language.
>
> So i have change few things in the login pagina,
> but it doesn't change my language.
>
> Does someone know the solution ?
>

Try using LocaleMiddleware if you don't use it at the moment:
http://code.djangoproject.com/browser/django/tags/releases/1.2.3/django/middleware/locale.py

You can also manually pick active locale with
django.utils.translation.activate() function.

--
Tomasz Zielinski

-- 
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: New project, debating postgresql or MySQL (Amazon RDS), does it matter to Django?

2010-06-26 Thread Tomasz Zieliński
On 25 Cze, 19:13, Eric Chamberlain  wrote:
> Hello,
>
> We have a new project and are debating whether to use postrgresql (Amazon 
> EC2) or MySQL with InnoDB tables (Amazon RDS).  It looks like our TCO would 
> be much lower using Amazon RDS.
>
> Our past Django experience has been with postgresql, does MySQL InnoDB have 
> any problems with Django's transaction middleware?
>
> We aren't using any custom fields, are there functional differences between 
> the two databases that would impact how we use Django?  
>

Take a look at this: 
http://www.slideshare.net/gplessis/mysql-on-amazon-rds-vs-ec2
RDS is pretty much a no-brainer, but it cannot be tuned like a custom
instance.

Regarding transactions - I have experience with one medium-sized
startup running on RDS (so it's MySQL+Innodb, formerly it was custom
instance but they switched for convenience), and things Just Work As
Advertised, but you have to remember about one subtle detail, that I
once commented here:

http://stackoverflow.com/questions/2235318/how-do-i-deal-with-this-race-condition-in-django/2235624#2235624

Other than that everything has so far been smooth, at least in my
operations.

Ah, and to save you pulling your hair:
- create MySQL database with CREATE DATABASE name CHARACTER SET UTF8;
- set DATABASE_OPTIONS to {"init_command": "SET
storage_engine=INNODB",}, at least for syncdb. Otherwise your tables
might be created as MyISAM.
Both of these are documented:
http://docs.djangoproject.com/en/dev/ref/databases/#creating-your-database
http://docs.djangoproject.com/en/dev/ref/databases/#creating-your-tables
- but it's easy to overlook them

As for comparision between MySql+InnoDb and PostgreSQL, I don't have
that much experience with the latter so I won't comment on this.
Two transaction-related differences that I'm aware of are:
- PostreSQL requires ROLLBACK of failed transaction, whereas MySQL
doesn't;
- MySQL backend doesn't support savepoints, even though MySQL itself
handles them. I asked this question on this group some time ago
(http://groups.google.com/group/django-users/browse_thread/thread/
ea3421933ea8c199), but noone answered.

--
Tomasz Zielinski
http://pyconsultant.eu

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



IntegrityError: (1062, “Duplicate entry ‘1830327 -1792993’ for key ‘some_instance_A_id’”) but no UNIQ UE constraint

2010-06-24 Thread Tomasz Zieliński
Maybe someone here knows this problem:

http://stackoverflow.com/questions/3079890/integrityerror-1062-duplicate-entry-1830327-1792993-for-key-some-instance

?

It happens rarely, randomly (although it might not be really random)
and currently I don't have idea what to look for to fix it (it also
doesn't have high priority for me, but if some of you knows this
problem then I'll be happy to fix it sooner than later).

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: how to avoid "in" query for large sets?

2010-05-24 Thread Tomasz Zieliński


On 24 Maj, 08:58, Daniel Roseman  wrote:
>
> User.objects.filter(id__in=Quiz.objects.filter(score__gt=90))
>

Nice thing, is it documented somewhere (I think I haven't this
before) ?

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: Uploaded File Security

2010-05-20 Thread Tomasz Zieliński


On 20 Maj, 04:19, Mike Dewhirst  wrote:
>
> If it has to be secure rather than just wishful thinking the webserver
> must demand credentials. If you are using Apache, that means .htaccess
> files which point to a list of credentials for each group.
>

What is the difference between long, random filename and login
+password?


--
Tomasz Zielinski
http://pyconsultant.eu

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



MySQL and transaction savepoint

2010-05-17 Thread Tomasz Zieliński
I've just discovered that MySQL supports savepoints.
If so, then what is the reason of Django MySQL backend not supporting
it?
Is this Django limitation, MySQLdb limitation or there is some other
reason?

--
Tomasz Zieliński
http://pyconsultant.eu

-- 
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: Inconsistency between DB Query Results Between Threads

2010-04-28 Thread Tomasz Zieliński


On 28 Kwi, 22:04, Jared Smith  wrote:
> Using Django DB API I have two threads one that increments a counter getting
> stored to the database and then another thread that is reading this counter.
>
> T1(Thread 1) increments
> T2(Thread 2) reads
>
> I have found that if I increment and store the counter value in T1 and then
> if I fetch it in the same thread I get the correct answer for the counter.
> The fetched number matches what I store.
>
> However I notice that if T2 reads after T1 stores the value there is some
> lag where it gives the wrong answer even though T1 is able to successfully
> read the value with the same exact method.  I put a loop spinning reading
> this value and within a second or two it seems to get the right answer.
>
> Is there some lag for different threads to get the same results due to some
> per thread caching happening under the covers?  Anyone know of a work around
> to make sure this cache is flushed?  I'm worried I could get this problem
> more generally since there are multiple threads accessing the DB and I need
> to make all of them get the most recently committed value.
>
> Thank you for any advice,
>

I'm guessing that this is happening to you:

http://stackoverflow.com/questions/2235318/how-do-i-deal-with-this-race-condition-in-django/2235624#2235624

Note that you can also lower the isolation level to READ COMMITED (in
case of MySQL)
to get similar result, but READ COMMITED is allegedly (I read it
somewhere) less used
and therefore less tested that default REPEATABLE READ.

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: I want "DEBUG = False" but still get the DEBUG data logged

2010-04-27 Thread Tomasz Zieliński


On 27 Kwi, 14:52, Tomasz Chmielewski  wrote:
> Am 27.04.2010 14:08, Tom Evans wrote:
>
> > If DEBUG is False, it will email any errors to ADMINS - is this not 
> > sufficient?
>
> Technically, should be fine, thanks.
>
> But I just checked, and I'm not getting any emails.
>
>      ADMINS = (
>          ('Tomasz Chmielewski','@wpkg.org'),
>      )
>
> I.e. the MTA running on the same server does not log any new attempts,
> as I would get with "echo test | mail -s test someemail".
>
> Am I still missing some setting?
>

Maybe email settings are not valid: 
http://docs.djangoproject.com/en/1.1/ref/settings/#email-host
?

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: Non-conventional use of django templates.

2010-04-17 Thread Tomasz Zieliński


On 16 Kwi, 19:22, Paweł Roman  wrote:
>
> Did anyone use a django template language in that fashion in a web
> application that, itself is written in django? Does it make sense? Is
> it safe?
>

I did, but it's been used by trusted set of users, so there were not
that many safety measures built in.

Regarding tag processing, it might be harder than I think, but I don't
see
a problem with cutting such unwanted tags, e.g. with regex or maybe
even
by cloning source code for templates and removing set of tags (OR
maybe
it's possible to disable some of tags, I've never checked this).

As for missing variables not failing silently - there is
TEMPLATE_STRING_IF_INVALID
setting that you might use.
And for filters - I'm not 100% sure at the moment, but believe that
failing (raising) filter
produce TemplateSyntaxError.

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: TemplateSyntaxError in the admin pages

2010-04-05 Thread Tomasz Zieliński


On 5 Kwi, 10:25, Martin Lundberg  wrote:

> File "/home/marlun/.virtualenvs/django/lib/python2.6/site-packages/
> django/template/debug.py" in render_node
>   81.             raise wrapped
>
> Exception Type: TemplateSyntaxError at /admin/timetrack/work/
> Exception Value: Caught an exception while rendering: not enough
> arguments for format string

Take a look at Django source:

http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/template/debug.py#L76

- that 'raise wrapped' line is placed in catch-all handler, which
means that
probably some of your code called during template rendering is
broken,
Django catches it and re-raises as TemplateSyntaxError which,
unfortunately,
is vague about ther real problem.

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: cascade deletion happens before pre_delete signal is sent?

2010-04-03 Thread Tomasz Zieliński


On 3 Kwi, 16:05, msoulier  wrote:
> I have a model A, which has a ForeignKey to model B.
>
> A --> B
>
> When B is deleted I want to save the As that are pointing at B by
> repointing them at a different B if possible. To do this I have a
> pre_delete signal registered for B models. Unfortunately does doesn't
> work.
>
> Django follows the relationship from B to A, and deletes the As before
> signaling the pre_delete event for B. So, and event that could save
> the As happens too late.
>
> Now, I could use a pre_delete for A, but then I won't know that the A
> is about to be deleted as a direct result of B being deleted, so I
> can't possibly tell that B is about to go away, so I should move the
> pointer to B to another B. This could simply be an admin directly
> deleting an A.
>
> So, signals fail me here, do they not? The only way to do this is to
> override the delete method in B and take action there instead. I'd
> prefer to avoid that by using signals.
>

I believe that this question was asked on this group a long time ago,
and the answer was that pre_delete signal was fired *before* actual
deletion occured,
but *after* objects were collected for deletion (i.e. after list of
objects that were to be deleted
was created - you can think of this list as of "deletion tree" show in
Django admin).

Writing this, I don't know if you've observed the same problem.

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: transactions

2010-03-31 Thread Tomasz Zieliński


On 31 Mar, 06:04, Continuation  wrote:
> On Mar 30, 8:33 am, Tomasz Zieliñski
>
>  wrote:
> > If you take a look at TransactionMiddleware source:
>
> >http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
>
> > then you'll see that it's just commit_on_success in disguise:
>
> >http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
>
> So that means I don't need TransactionMiddleware if I use
> @transaction.commit_on_success, right?

If you put @transaction.commit_on_success explicitly in your code,
then you're doing TransactionMiddleware manually, so the answer is
yes.

>
> > Also, you can take a look at my post here, to avoid some transaction-
> > related problems in future:
>
> >http://stackoverflow.com/questions/2235318/how-do-i-deal-with-this-ra...
>
> Thanks.
>
> I assume that calling transaction.commit() after the IntegrityError
> exception is to refresh the frozen view. But I'm not sure I understand
> why transaction.commit() would do that. Can you elaborate?

Because on default MySQL isolation level, i.e. REPEATABLE READ,
view (or snapshot) of db table is frozen after first access to it
(there are some more detail's to it).
To get new snapshot you have to open new transaction, and that's what
commit do.

http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html#isolevel_repeatable-read

(Note that in above link they say about SELECT, and I don't remember
if create() also
SELECTs or it's INSERT that freezes table, but the fact is table
become frozen for transaction).

>
> Also in your stackoverflow answer you said the default for MySQL is
> AUTOCOMMIT=OFF. but in the Django doc (http://docs.djangoproject.com/
> en/dev/topics/db/transactions/) it was stated that
>
> "Django's default behavior is to run with an open transaction which it
> commits automatically... This is much like the auto-commit setting for
> most databases."
>
> So is auto-commit on or off by default?

It's the tricky part. There are *two* auto-commits - one is in DB,
and second one is in Django.

Autocommit in DB is OFF by default (according to Python DB API spec,
and Django doesn't seem to change that), whereas Django autocommit
is turned ON by default (and documentation is not clear here).

DB autocommit is something you can read about in DB docs,
(for MySQL Innodb: 
http://dev.mysql.com/doc/refman/5.0/en/innodb-transaction-model.html)
where as Django autocommit is simple mechanism that calls db COMMIT
after
each query that modifies db (e.g. INSERT caused by save()) - and
that's the whole magic.

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: transactions

2010-03-30 Thread Tomasz Zieliński
On 30 Mar, 07:24, Continuation  wrote:
> If I have a view function that transfers money from savings to
> checking account, is @transaction.commit_on_success the recommend way
> to manage the transaction?
>
> So something like:
>
> @transaction.commit_on_success
> def transfer(request):
>     ...
>     savings.withdraw(amount)
>     checking.deposit(amount)
>
> If I use @transaction.commit_on_success, do I still need
> django.middleware.transaction.TransactionMiddleware?
>
> And all other database interactions will remain auto-commit, correct?
>

If you take a look at TransactionMiddleware source:

http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/middleware/transaction.py

then you'll see that it's just commit_on_success in disguise:

http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/db/transaction.py#L228

Also, you can take a look at my post here, to avoid some transaction-
related problems in future:

http://stackoverflow.com/questions/2235318/how-do-i-deal-with-this-race-condition-in-django/2235624#2235624

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: Multiple tables, is Django suited for this?

2010-03-30 Thread Tomasz Zieliński
Just an idea based on my experience - I'm able to plug on/off tables
on the fly, using database VIEWs.
Such VIEW can be bound to Django model with Meta: managed = False, and
you can bind anything you want
to it (I mean - arbitrary SELECT).

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: model design and derived classes - need advice please?

2010-02-02 Thread Tomasz Zieliński
On 2 Lut, 16:06, Simon Davies  wrote:
> Hi
>
> I am writing a web shop.  I have a shopping cart class, which has a
> many to many relationship to an item class, the item class has three
> derived classes.  The basic schema is shown below:
>
> class Item(models.Model):
>         title = models.CharField(max_length=100)
>         description = models.CharField(max_length=500)
>         price = models.DecimalField(max_digits=7, decimal_places=2,
> verbose_name=u'Price (£)')
>
> class Bike(Item):
>         manufacturer = models.CharField(max_length=50)
>
> class BikePart(Item):
>         partType = models.CharField(max_length=50, choices=PARTTYPE_CHOICES)
>
> class Accessory(Item):
>         accessoryType = models.CharField(max_length=50,
> choices=ACCESSORYTYPE_CHOICES)
>
> class Cart(models.Model):
>        items = models.ManyToManyField(Item)
>
> The cart has a manytomany relationship with the item superclass.  How
> is it possible to get the derived class back though from the
> superclass that is stored in the Cart.items field, or is there a
> better way of doing this.  Will I have to resort to queries through
> all of the derived classes checking for the id's that match those of
> the objects in Cart.items so something like this:
>
> for elem in cart.items.all():
>    b = UsedBike.objects.all().filter(id=elem.id)
>
> or is there a neater way of doing this.
>

This is a `standard` problem with relational databases,
there are several solutions you can find on google, but
neither of them is perfect, IMO.

You can also take a look at this:

http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/

- maybe it can solve your problem.

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: Gathering performance statistics

2010-02-02 Thread Tomasz Zieliński
On 2 Lut, 00:22, gkelly  wrote:
> Hello,
>
> I'm wondering if anyone knows of an existing middleware that does the
> following:
>
> - collects usage and performance statistics (i.e. logs each request to
> a URL and its response time)
> - performs some simple summaries of logged data
>
> Or, if anyone knows how to do this with Google Analytics, please point
> me in that direction.

Maybe this: http://code.google.com/p/django-tracking/
(I haven't used it personally)

For more comprehensive research, you can try:

http://www.google.com/search?hl=en=code.google.com=code.google.com=django-+=code.google.com=f==


--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: where can i see the tables created in sqlite database

2010-02-02 Thread Tomasz Zieliński
You can also google for "sqlite database browser",
which is simple but nice GUI tool for browsing SQLite databases.

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: Select *Latest* Grade Information for every Student

2010-01-31 Thread Tomasz Zieliński


On 29 Sty, 03:16, marsanyi  wrote:
> The joy of annotate().  In Django 1.1 and above:
>
> result = Student.objects.annotate(latest = models.Max('grades__date'))
>
> gives you the recordset, sans test_name.  Any advances on this?
>

I would suggest:

students = Student.objects.annotate(latest_grade_pk=models.Max
('grades__pk'))
latest_grades = Grade.objects.filter(pk__in=[st.latest_grade_pk for st
in students])

Filtering on dates can choke on two identical dates.

More on this:

http://stackoverflow.com/questions/2074514/django-query-that-get-most-recent-objects-from-different-categories/2076665

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: getting the object with max value

2010-01-25 Thread Tomasz Zieliński
On 25 Sty, 07:38, Kenneth Gonsalves  wrote:
> hi,
>
> I have a model 'Player' and a Model 'Handicap'. Handicap will have several
> fields, one of which is a foreign key to player. Now I need to get the 
> Handicap
> instance when the player had the highest handicap. I can use Max to find the
> highest handicap and do a query to identify the instance where the handicap is
> at Max value. Is there a simpler way of doing this?
>

I'm not sure if I understand correctly, but you are probably asking
for something like this:

http://groups.google.pl/group/django-users/browse_thread/thread/3b3cd4cbad478d34/3e4c87f336696054?hl=pl=
http://stackoverflow.com/questions/2074514/django-query-that-get-most-recent-objects-from-different-categories/2076665

--
Tomasz Zielinski
http://pyconsultant.eu

-- 
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: unexpected Error: OperationalError: no such column: ...

2010-01-20 Thread Tomasz Zieliński
On 20 Sty, 20:52, HWM-Rocker  wrote:

> o...@olaf-laptop:~/workspace/truemen$ ./manage.py shell

Not touching you question, you could try shell_plus from django-
extensions,
it load all models on startup, saving you a lot of typing.
Moreover you could try ipython (which is used by shell/shell_plus if
only is available).

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Load template tags if installed?

2010-01-16 Thread Tomasz Zieliński
On 16 Sty, 20:31, "Aaron C. de Bruyn"  wrote:
> Am I missing an easy way to check if an application is installed
> so I can make decisions in a template?
>
> I have an application that currently requires the comments framework
> and django-attachments.
>
> I would rather make them optional depending on the functionality needed
> by the user/hoster of my app.
>
> I don't see a way in the templates to say something like:
> {% if installed django.contrib.comments %}
>   display the comment form
> {% endif %}
>
> I would rather not have 5 different templates for the same page, each
> one with a different combination of possible installed applications along
> with views to figure out which of the templates to load.
>

AFAIK there is no such feature, but I think you could
write template context processor exposing necessary flags to
templates.

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Custom filters and partial mark_safe?

2010-01-15 Thread Tomasz Zieliński
On 15 Sty, 10:28, Andrew Turner  wrote:
> I have a custom filter parses a CharField for usernames marked with
> '@', and replaces them with a hyperlink to their profile page:-
>
> (...)
>
> I'm trying to mark_safe only the hyperlinks so that they are not
> autoescaped, but mark_safe only seems to work if I apply it to the
> returned string as a whole, which would be unsafe.
>
> Is this at all possible?
>

I'm not 100% sure, but after doing quick review of django/utils/
safestring.py,
I would say that string is either safe or unsafe, it cannot be only
half-safe.

(Disclaimer - Django license applies :)
http://code.djangoproject.com/browser/django/tags/releases/1.1.1/LICENSE):

def mark_safe(s):
"""
Explicitly mark a string as safe for (HTML) output purposes. The
returned
object can be used everywhere a string or unicode object is
appropriate.

Can be called multiple times on a single string.
"""
if isinstance(s, SafeData):
return s
if isinstance(s, str) or (isinstance(s, Promise) and
s._delegate_str):
return SafeString(s)
if isinstance(s, (unicode, Promise)):
return SafeUnicode(s)
return SafeString(str(s))

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Querysets returns wrong result when using threading.

2010-01-15 Thread Tomasz Zieliński


On 15 Sty, 05:33, James Bennett  wrote:
> On Thu, Jan 14, 2010 at 10:26 PM, Kieran Brownlees  
> wrote:
> > Basic example of format:
> > Main Thread: print objects.all()
> > Spawned Thread: print objects.all() -- same as main thread
> > Main Thread: objects.create(newObj)
> > Main Thread: print.objects.all() -- correct queryset, original + new
> > Spawned Thread: print objects.all() -- only contains the original
> > objects, not the new one?
>
> This would be the expected result with the default transaction
> isolation of most databases, and has nothing to do with threading.
>

To be more explicit - Python DB API spec states that connection
should, by default, have autocommit turned on - which means that there
is always an ongoing transaction at DB level.

Now, for MySQL backend, which I'm most familiar with,
default isolation level is REPEATABLE READ, which means
that first access to given table freezes its state for the duration
of current transaction.

And because Django default behaviour is @autocommit,
i.e. it doesn't issue any COMMIT/ROLLBACK statements
for fetches, only for writes, all subsequent queries results
in the same queryset (in terms of elements, not object id).

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: How to pass raw sql results (cursor.fetchall()) to the template?

2010-01-15 Thread Tomasz Zieliński
On 14 Sty, 23:01, Ken  wrote:
> Newb question here.  How do I pass raw sql results to my template?
> The sql results contains a two column queryset with several rows .
>
> Below doesn't work.  How do I make this work?  Do I need to parse the
> results into an array and then pass to the template?
>
> IN THE VIEW:
> cursor = connection.cursor()
> cursor.execute("query goes here")
> results = cursor.fetchall()
>
> return render_to_response('template.html', {'results': results})
>
> IN THE TEMPLATE:
> {% for result in results %}
>     {{ result[0] }} is a big {{ result[1] }}
> {% endfor %}

I haven't checked this in shell, but it looks to be correct,
except that you should write: {{ result.0 }} instead of {{ result
[0] }}

Here's the relevant doc section:

http://docs.djangoproject.com/en/1.1/topics/templates/#variables

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: need for caching POST requests

2010-01-13 Thread Tomasz Zieliński
On 13 Sty, 11:09, Hinnack  wrote:
> there must be done more then this - e.g. the value of the key the data is
> stored in cache has to be calculated from POST vars
> instead of URL alone

Why don't you take a look yourself:

http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/core/cache
http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/middleware/cache.py

- it's quite readable piece of code

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Model inheritance

2010-01-13 Thread Tomasz Zieliński
On 12 Sty, 20:52, a b  wrote:
> Hi,
>
> I have three models:
> Product
> SimpleProduct that extends Product
> GroupProduct that extends Product and have ManyToMany relation with
> SimpleProduct
>
> The reason to use the base Product model is so I can use paging.
> Is it possible to make a query that gives a list of GroupProducts and
> SimpleProducts that are not included in a GroupProduct.
> I don't want to show the same product twice, once standalone and once as
> part of a GroupProduct.
>
> I can add a field to SimpleProduct that indicates weather it's standalone or
> not and maybe update it using signals
> but it doesn't feel like the right way.
>

Quick, untried, ideas:

1. You could try using aggregation:

from django.db.models import Count
SimpleProduct.objects.annotate(belongs_to_groupproducts=Count
('groupproduct')).filter(belongs_to_groupproducts=0)

2. If this is "normal" inheritance (i.e. not an abstract one), then
SimpleProduct and GroupProduct have
implicit OneToOneField connecting them to Product. It means that you
probably could just filter Product-s and then downcast it.

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Migrating Many-To-Many Relationship

2010-01-13 Thread Tomasz Zieliński


On 12 Sty, 22:53, David Nolen  wrote:
> When migrating an existing db how do you create a proper join table
> for a ManyToMany field. I think I've got it mostly worked out except
> for the bit that looks like this in Django generated SQL:
>
> CREATE TABLE `blog_posts_authors` (
>   `id` int(11) NOT NULL AUTO_INCREMENT,
>   `post_id` int(11) NOT NULL,
>   `user_id` int(11) NOT NULL,
>   PRIMARY KEY (`id`),
>   UNIQUE KEY `post_id` (`post_id`,`user_id`),
>   KEY `user_id_refs_id_ea0040bf` (`user_id`) /* <= GENERATED ?
> */
> ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
>
> Django creates some kind of random key, If I generate a random key in
> my own join table will Django automatically use this?
>

KEY is just INDEX, and AFAIK Django doesn't refer to indices anyway,
they are used internally by MySQL, to speed up queries.

By the way, South.aeracode.org is a great library for performing
migrations,
it takes care of such low-level details.

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: m2m in views

2010-01-13 Thread Tomasz Zieliński


On 12 Sty, 23:24, shaner  wrote:
> I'm trying to make a model's detail view, take movies for example;
> actors are m2m to movies
>
> this works but it doesn't feel right is there, i pass this context to
> the template where i for loop through the actor list
>
> >>> Movie.objects.filter(pk=movie_id)[0].character.all()
>
> [, ]

It looks like in template you have somehing like {{actors}}
that simply converts list to string.

What you probably need, is something like:

{% for actor in actors %} {{actor.full_name}} {% endfor %}

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: need for caching POST requests

2010-01-13 Thread Tomasz Zieliński


On 13 Sty, 07:54, hinnack  wrote:
> Hi,
>
> I need to cache POST requests, too, on certain requests.
> The requests are not changing data, but imagine an XMLRPC
> service (that is based on POST requests only per spec anyway) uses
> functions, that always return the same like 2 + 2 SHOULD always
> return 4 :-) The site I have could use the caching-middleware, if it
> would support POST, as no request changes data.
>
> Now the whole caching mechanism of django only supports GET
> (as far as I know).
> Has someone tried on caching POST requests?
> Is someone else interested in caching POST requests? (is this more
> something for django core or should I write a decorator)
>

I would say that this is no different than caching GET requests.
If you take a look at django cache middlewares (django/middleware/
cache.py),
then you quickly notice that there are lines like:

if not request.method in ('GET', 'HEAD') or request.GET:
request._cache_update_cache = False
return None # Don't bother checking the cache.

So you should quickly be able to just adapt that to you need by
including
POST request under some conditions.

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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.




Best way to fix django admin preview of flatpage attached to multiple sites

2010-01-11 Thread Tomasz Zieliński
I have flatpage attached to multiple sites. Its admin preview chooses
arbitrary site,
which is quite obvious after debugging up to lines 35-36 of
django.contrib.contenttypes.views.shortcut().

What would be the best way of fixing this problem?

I see that mentioned shortcut() function receives request object, so I
could just
extract host from there, but I prefer not to patch live server.

I haven't looked at catching admin url yet , so maybe someone can
suggest some nice solution?

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Mysterious transactions wrapping views without middleware.

2010-01-11 Thread Tomasz Zieliński


On 10 Sty, 02:38, apramanik  wrote:
> Thanks! That partially fixes my problem. I wrapped a function with
> commit_on_success and it doesn't rollback the changes if it throws an
> IntegrityError coming from PostgresSQL:
>
> @transaction.commit_on_success
>     def add_destination( self, placemark, trip, user,
> \
>                         description = None, status =
> Item.SUGGESTED ) :
>
>         ...
>
>         # create the
> destination
>         destination = self.create(creator = user, description =
> description,
>                 status = status, location = location, trip =
> trip)
>
>         ...
>
> So, if that create throws an IntegrityError, the transaction is *not*
> rolled back. If I place "transaction.set_dirty()" before the create,
> the transaction is rolled back. Seems like a bug.
>

I'm not that sure - if there is fresh transaction and first statement
in it is INSERT,
and that insert fails, then the transaction is still empty - so there
is nothing
to be rolled back.

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: How to get ModelAdmin given a Model

2010-01-11 Thread Tomasz Zieliński
On 11 Sty, 16:23, Marco Rogers  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.
> 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 info.
>
> http://groups.google.com/group/django-users/browse_thread/thread/0cd0...

Maybe something like this:

1. Write something like django.contrib.admin.autodiscover, to get all
ModelAdmins
2. Iterate those ModelAdmins, retrieve models they are attached to and
store this mapping in a dict.
3. def get_admin(model):
return admin_to_model[model]

?

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: text in translation strings?

2010-01-11 Thread Tomasz Zieliński


On 10 Sty, 12:59, Andreas Pfrengle  wrote:
> I'm having a template, where a link shall be inside a translation-
> marked text. I see two ways how to accomplish this, but both don't
> work:
> 1. {% trans "You need to login before
> you can do anything" %}
(...)
> 2. {% blocktrans %}You need to login
> before you can do anything {% endblocktrans %}
(...)
>
> Is there a way with either of these tags to accomplish what I want?
>

I haven't tried this but maybe it will work:

{% url login as login_url %}
{% blocktrans %}You need to login before
you can do anything {% endblocktrans %}

I'm curious if this is good guess, so please let me know.

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Handling Vector/Array Data in Forms

2010-01-09 Thread Tomasz Zieliński
On 9 Sty, 01:23, datta  wrote:
> I am using Django for a scientific applicaition. If I have to
> transport a vector/array 'to' a form, dismantle it and display the
> relevant information, it is easy. But how I capture vectors/array
> datatypes 'from' the HTML forms (submitted by the user) in the
> view.class and work with them.
>
> i.e., i am asking if there is a efficient way of handling 'array' data
> types in forms (other than using a single variable name in the (html)
> form and doing a get_all from the (parent) request object)
>

I'm not sure what you are asking for, but request.POST['vector']
contains
list or tuple of values gathered from vector=1=2&(etc...) POST
data.

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Creating UML diagram from my django models

2010-01-09 Thread Tomasz Zieliński
On 9 Sty, 15:46, Gaffar Durmaz  wrote:
> i wanna creating UML or ER diagram from my models..
> is there any tools to creating automatically ?
> so i use Eclipse IDE.. maybe eclipse plugins or other..

I'm not sure if this would satisfy you:

http://code.google.com/p/django-command-extensions/wiki/GraphModels

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: request.LANGUAGE_CODE-sensitive choices in forms.ChoiceField?

2010-01-07 Thread Tomasz Zieliński


On Jan 7, 4:23 pm, Andreas Pfrengle  wrote:
> On 7 Jan., 13:22, Tomasz Zieliñski 
>
> > > MyForm(forms.Form):
> > >     myfield = forms.ChoiceField(choices=CHOICES)
>
> > 1. Maybe you could use ModelChoiceField:
>
> >http://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield
>
> > 2. You could populate choices on each request, by writing custom
> > __init__ in MyForm:
>
> > def __init__(self, post=None, request=None):
> >         if post:
> >             super(MyForm, self).__init__(post)  # bound form
> >         else:
> >             super(MyForm, self).__init__()  # unbound form
>
> >         self.fields['myfield'].choices = zip(
> >     [x.number for x in MyModel.objects.all()],
> >     [x.locale.get(lang=request.LANGUAGE_CODE).name for x in
> > MyModel.objects.all()]
>
>
> Hello Tomasz,
>
> thanks for the quick answer, however your first suggestion doesn't
> work, since I don't want a queryset, I just want to display a field of
> a related model for every model in the queryset.

It was just in case you don't know about it.

> The second variant seems to work, even though I always get the result
> for German language. But I suppose the problem is rather untested i18n
> in my project than the formfield
> However I'm wondering how I would transform this concept on Formsets.
> I think I would somehow need to expand already the formsets __init__
> to accept the additional 'request' parameter (otherwise I get "__init__
> () got an unexpected keyword argument 'request'"), and then push it
> forward to the forms __init__.

I'm not sure here as I only modified Form. But I suspect that you
could modify FormSet __init__ as well (although quick scan of FormSet
sources has revealed some complexity there).

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: auth unit tests fail because sites isn't used

2010-01-07 Thread Tomasz Zieliński

On Jan 6, 10:01 pm, msoulier  wrote:
> I can't find anywhere in the django docs where it says that
> django.contrib.auth uses django.contrib.sites, but when I run my unit
> tests I get this
>
> (...)
>
> --
> Ran 45 tests in 22.375s
>
> FAILED (errors=1)
>
> I don't need the sites app, but it looks like auth needs it. Is that
> correct?
>
> It would be nice to just supress this test from running...
>

I'm also getting this, so I'm only running my own tests (by passing
app names to test).

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: request.LANGUAGE_CODE-sensitive choices in forms.ChoiceField?

2010-01-07 Thread Tomasz Zieliński
On Jan 7, 1:04 pm, Andreas Pfrengle  wrote:
> Hello,
>
> I am trying to implement a ChoiceField that's choices shall be
> calculated during form instantiation in the view depending on the
> users preferred language (according to request.LANGUAGE_CODE from
> LocaleMiddleware).
>
> Example forms.py:
> CHOICES = zip(
>     [x.number for x in MyModel.objects.all()],
>     [x.locale.get(lang=request.LANGUAGE_CODE).name for x in
> MyModel.objects.all()]
> )
> #locale is the manager from an generic relation (http://
> docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1)
>
> MyForm(forms.Form):
>     myfield = forms.ChoiceField(choices=CHOICES)
>

1. Maybe you could use ModelChoiceField:

http://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield

2. You could populate choices on each request, by writing custom
__init__ in MyForm:

def __init__(self, post=None, request=None):
if post:
super(MyForm, self).__init__(post)  # bound form
else:
super(MyForm, self).__init__()  # unbound form

self.fields['myfield'].choices = zip(
[x.number for x in MyModel.objects.all()],
[x.locale.get(lang=request.LANGUAGE_CODE).name for x in
MyModel.objects.all()]

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Saving several copies of an object

2010-01-05 Thread Tomasz Zieliński


On 5 Sty, 19:11, Matthias Kestenholz <matthias.kestenh...@gmail.com>
wrote:
> 2010/1/5 Tomasz Zieliński <tomasz.zielin...@pyconsultant.eu>:
>
>
>
>
>
>
>
> > On 5 Sty, 18:16, pjmorse <flashesofpa...@gmail.com> wrote:
>
> >> This is done by looping over the list of languages and saving a
> >> NewsTrans in each language. The source language is marked as already
> >> translated, the other two are not (that is, they still need
> >> translating).
>
> >> The problem is that this is done with ns.save() (where ns is a
> >> NewsTransForm with the submitted data), and what's actually happening
> >> is that one NewsTrans is created, then it is updated twice, ending in
> >> the third language.
>
> >> I thought I could fix this with ns.save(force_insert=True) but that
> >> throws errors instead: "save() got an unexpected keyword argument
> >> 'force_insert'".
>
> > Take a look at this:
>
> >http://docs.djangoproject.com/en/1.0/ref/models/instances/#how-django...
>
> > - after first ns.save() 'ns' receives primary key (id), which in turn
> > causes any subsequent
> > ns.save() to UPDATE previously created row. I'm not sure why
> > 'force_insert' is an unexpected
> > argument, but it doesn't make sense anyway to use it.
> > You can try ns.id = None; ns.save() instead.
>
> This won't do it, because ns is a Form, not a Model object. Something
> like this might work though:
>
> obj = ns.save(commit=False)
>
> for language in languages:
>     obj.id = None
>     obj.language = language
>     obj.save()
>

Ah, right, I overlooked the information about ns being a form.. Sorry
then.

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Project optimisation stage: Advice to boost speed of database queries across tables?

2010-01-05 Thread Tomasz Zieliński


On 4 Sty, 07:30, Sam Walters  wrote:
> Hi Tomasz
> Yes, i have followed a raw sql approach now im looking at my test data
> to see which objects have multiple rows and cleaning that up.
>
> Its a shame that '__in' has limited use under these scenarios:
>
> directories = search_querySet.distinct()
> addresses = Address.objects.filter(directory__in=directories)
> addresses.values('directory__id', . *some other relevent fields*)
>
> this certainly allows me to select the related sets of addresses for
> each directory however i need to be able to relate each address object
> back to its directory (by id would be great) trying to get the
> directory 'id' packaged in the values() gives me an error saying
> invalid field even though 'directory' is listed as a valid field.

I'm not 100% sure, but AFAIR you can only take values of fields
contained directly in models.

> If i could do that then i could iterate through each dictionary and
> zip related items together based on their directory id's or something
> nice like that.
>
> "
> Re those VIEWs, they are SELECTs with JOINs, which effectively
> produce up to a few rows for single object (e.g. if you have person
> with 3 phone numbers,
> you're getting 3 rows), but it turns out to be much more efficient to
> process/merge
> that in Python code than to issue hundreds of SQL queries.
> "
>
> Yes this seems to be the best way, do you have any links where i can
> see how various people have implemented this? Would be good to write a
> 'pythonic' solution
>

I wrote simple function that works for my purposes, I suspect that
you use-case also doesn't require anything fancy, but I agree
that 'pythonic' solutions are good for morale :-)

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: database password in settings.py

2010-01-05 Thread Tomasz Zieliński


On 5 Sty, 17:49, Eric Chamberlain  wrote:
> There's nothing special about settings.py.  You could do something like:
>
> from Crypto.Cipher import Blowfish
>
> blowme = Blowfish.new(SECRET_KEY)
> DATABASE_PASSWORD = blowme.decrypt(ENCRYPTED_PASSWORD)
>
> Securing SECRET_KEY is left as an exercise for the reader.

It's piece of cake:

blowme0 = Blowfish.new(SECRET_KEY0)
SECRET_KEY = blowme0.decrypt(ENCRYPTED_SECRET_KEY)

;-)

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: Saving several copies of an object

2010-01-05 Thread Tomasz Zieliński


On 5 Sty, 18:16, pjmorse  wrote:
>
> This is done by looping over the list of languages and saving a
> NewsTrans in each language. The source language is marked as already
> translated, the other two are not (that is, they still need
> translating).
>
> The problem is that this is done with ns.save() (where ns is a
> NewsTransForm with the submitted data), and what's actually happening
> is that one NewsTrans is created, then it is updated twice, ending in
> the third language.
>
> I thought I could fix this with ns.save(force_insert=True) but that
> throws errors instead: "save() got an unexpected keyword argument
> 'force_insert'".
>

Take a look at this:

http://docs.djangoproject.com/en/1.0/ref/models/instances/#how-django-knows-to-update-vs-insert

- after first ns.save() 'ns' receives primary key (id), which in turn
causes any subsequent
ns.save() to UPDATE previously created row. I'm not sure why
'force_insert' is an unexpected
argument, but it doesn't make sense anyway to use it.
You can try ns.id = None; ns.save() instead.

--
Tomasz Zielinski
http://pyconsultant.eu
-- 
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: button for filtering the admin changelist based on callable

2010-01-03 Thread Tomasz Zieliński
On 30 Gru 2009, 20:29, TeenSpirit83 
wrote:
> Hi,
> I have a  callable in the modeladmin for an object XX.
> Now I want to add a tool button (or something clickable) for filtering
> the changelist displaying only the object having  value less than
> 30.
> How would you implement somthing like this?
> Thanks a lot!

You could use default Django admin filtering but it's limited
to what database can do and doesn't support custom filters.

But it seems that there is some undocumented (?) possibility:

http://stackoverflow.com/questions/991926/custom-filter-in-django-admin

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: Project optimisation stage: Advice to boost speed of database queries across tables?

2010-01-03 Thread Tomasz Zieliński
On 31 Gru 2009, 01:56, Sam Walters  wrote:

> for s in search_querySet:
>         address_info = s.address_set.all() #.select_related(depth=2) -
> yes i can/will put select related here but it really does not help
> that much 20% tops
>         #address_info is usually 2-3 rows from an address table
>         for a in address_info:#.select_related(depth=2):
>             if a.addresstype.adrtype == 'Physical' and
> a.addradmin.addr_enabled == True:
>             #further reduction in the number of rows which we need to
> get values from.
>             related_phone=a.phone_set.all()
>             related_email=s.email_set.all()
>             #phones and emails are a small number of rows 2-3 tops
>
> It is these lines which produce the performance hit.
> I cant see a way of using django's query language to avoid having to
> descend into each of the 500 'directory' objects because of the
> necessity to get all rows from the related tables in phones an emails
> and to inspect the type of 'address' object.
>

I solved very similar problem by creating database VIEWs with data I
needed,
wrapping those VIEWs with unmanaged Django models and then using
simple .filter(...)-s.

Re those VIEWs, they are SELECTs with JOINs, which effectively
produce up to a few rows for single object (e.g. if you have person
with 3 phone numbers,
you're getting 3 rows), but it turns out to be much more efficient to
process/merge
that in Python code than to issue hundreds of SQL queries.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: Project optimisation stage: Advice to boost speed of database queries across tables?

2010-01-03 Thread Tomasz Zieliński


On 30 Gru 2009, 16:41, Nick Arnett  wrote:
>
> E.g.: SELECT `common_addresstype`.`id`, `common_addresstype`.`adrtype` FROM
> `common_addresstype` WHERE `common_addresstype`.`id` IN (1,6,8,52,173)
>
> I imagine there's an ORM query that will do the same thing, but I know MySQL
> far better than I know Django.
>

This is as simple as using .filter(addresstype__id__in=[1,6,8,52,173])

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: Custom template tag for a chaptered document?

2010-01-03 Thread Tomasz Zieliński
On 30 Gru 2009, 01:26, Stodge  wrote:
> I need to write a custom tag. I have a hierarchy of objects that I
> want to turn into a chaptered document. But I want to be able to build
> and display the document in a template AND generate a PDF or other
> format from a view. Can I write a custom template tag and use it in a
> template and from a view?? Or is there already something like this out
> there

You could write a function that does what you need and can be used in
views,
then write template tag as an thin adaptor around this function - so
that
you can use it in templates.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: How to unregister model?

2009-11-24 Thread Tomasz Zieliński
That patch is a hack that requires modifying live instance of Django,
moreover I don't know what is influenced by it as I'm not that
familiar
with inner workings of model layer, so using it would be troublesome
for me.

So it seems that I have to write custom delete()s, using raw SQL..

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: How to unregister model?

2009-11-24 Thread Tomasz Zieliński
On 24 Lis, 22:42, Tim Valenta  wrote:
> > I want my unmanaged models to literally disappear from Django sight,
> > and then re-appear on demand.
>
> That sounds rather hack-ish... I'm not sure Django can do that
> exactly.  I'm not familiar with the situation, exactly, so I'm unsure
> of what you might be able to do differently.
>

I'm suffering from something similar to this:

http://code.djangoproject.com/ticket/10829

- and I prefer to avoid hacking Django core, resorting to raw SQL etc.
I only I could hide those unmanaged models, things would be smooth
again,
even though it's not the cleanest solution.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: How to unregister model?

2009-11-24 Thread Tomasz Zieliński
On 24 Lis, 22:18, Tim Valenta  wrote:
> Sorry for double-post.
>
> Additionally, you might experiment with the Meta class attribute,
> "abstract = True" on your wrapper models.  

Thank you, I know about 'abstract' and I am using but unfortunately
it doesn't help me much. What I need is the ability to somehow hide
for a while non-abstract unmanaged models.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: How to unregister model?

2009-11-24 Thread Tomasz Zieliński
On 24 Lis, 22:15, Tim Valenta  wrote:
> 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)
>

The 'unregister' word seems to have been misleading, as I wasn't
referring
to admin panel at all :)

I want my unmanaged models to literally disappear from Django sight,
and then re-appear on demand.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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.




How to unregister model?

2009-11-24 Thread Tomasz Zieliński
Is there a way to unregister model from being seen by Django model
manager?
I have some unmanaged models that are wrappers around read-only
database views
and also have foreign keys to 'real' models.

Now, when I'm trying to delete instance of 'real' model that is
referenced by unmanaged model,
I'm getting OperationalErrors as Django tries to perform cascade
delete.

As a solution, I'd like to unregister my unmanaged models
before .delete(),
and re-registering them after, but I don't know how to do it.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: Problem with unmanaged models and unit testing

2009-11-24 Thread Tomasz Zieliński
Thank you for you responses, I think I spotted the problem.

My unmanaged model is in fact wrapper for database view.
It also inherits from Django abstract model that has ManyToManyField-s
onboard.

When trying to test my app, syncdb.py in line 93 tries to actually add
foreign key
pointing from m2m intermediate table to unmanaged model's table, which
of course
doesn't exist (in my regular app db views are pre-created manually).

BTW string ' #sql-710_139' doesn't appear in sql statement that causes
mentioned error,
the statement is perfectly ok.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: Many to many relation - parents without any children

2009-11-15 Thread Tomasz Zieliński


On 15 Lis, 09:34, Nagy Károly <char...@rendszergazda.com> wrote:
> Tomasz Zieli ski wrote:
> > How about something like this (should work, although I haven't checked
> > it):
>
> > Author.objects.annotate(article_num=Count('articles')).filter
> > (article_num=0)
>
> > - where articles=ManyToManyField('Article')
>
> This is so elegant, so i have to upgrade to 1.1 now... :)
>
> Thank you Tomasz
>

My pleasure. Upgrade should be straightforward and painless,
assuming you're on 1.0 now.

--
Tomasz Zieliński
http://pyconsultant.eu

--

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=.




Re: Many to many relation - parents without any children

2009-11-14 Thread Tomasz Zieliński


On 14 Lis, 23:20, Nagy Károly <char...@rendszergazda.com> wrote:
> Please help me in orm level filtering many-to-many relations.
>
> I have to filter all "authors" who does not belongs to any "articles".
> Or the opposite of this, list of orphaned articles...
>
> I dont want to write sql in the model if possible.

How about something like this (should work, although I haven't checked
it):

Author.objects.annotate(article_num=Count('articles')).filter
(article_num=0)

- where articles=ManyToManyField('Article')

--
Tomasz Zieliński
http://pyconsultant.eu

--

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=.




Re: Need help with Query: Q Objects and .extra()

2009-11-13 Thread Tomasz Zieliński
On 13 Lis, 20:58, Info Cascade <informationcasc...@gmail.com> wrote:
>  art_list = Article.objects.filter(status__status='PUBLISHED',
>                 QExtra(where=['title_tsv @@ plainto_tsquery(%s)'],
>                     params=[term])) |
> Q(tags__name__icontains=term)).distinct()

I'm not aware of any QExtra-like functionality (someone correct me
please if I'm wrong here),
but you can do two searches and manually merge the results in Python,
i.e.:

art_list_published = Article.objects.filter
(status__status='PUBLISHED')
art_list_results1 = art_list_published.extra(
where=['title_tsv @@ plainto_tsquery(%s)'], params=[term]))
art_list_results2 =  art_list_published.filter
(tags__name__icontains=term)
art_list_results_merged = set(art_list_results1+art_list_results2)

- I'm not sure if set will work here (IMO it should), but it's trivial
to replace it with custom merge


--
Tomasz Zieliński
http://pyconsultant.eu

--

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=.




[1.1] Problem with unmanaged models and unit testing

2009-11-13 Thread Tomasz Zieliński
Hello

I have a problem with when trying to test app that is using unmanaged
models:

(...)
Creating table sometable
Traceback (most recent call last):
  File "H:\myproject\manage.py", line 11, in 
execute_manager(settings)
  File "C:\Python26\lib\site-packages\django\core\management
\__init__.py", line 362, in execute_manager
utility.execute()
  File "C:\Python26\lib\site-packages\django\core\management
\__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python26\lib\site-packages\django\core\management\base.py",
line 195, in run_from_argv
self.execute(*args, **options.__dict__)
  File "C:\Python26\lib\site-packages\django\core\management\base.py",
line 222, in execute
output = self.handle(*args, **options)
  File "H:\myproject\south\management\commands\test.py", line 27, in
handle
super(Command, self).handle(*args, **kwargs)
  File "C:\Python26\lib\site-packages\django\core\management\commands
\test.py", line 23, in handle
failures = test_runner(test_labels, verbosity=verbosity,
interactive=interactive)
  File "C:\Python26\lib\site-packages\django\test\simple.py", line
191, in run_tests
connection.creation.create_test_db(verbosity, autoclobber=not
interactive)
  File "C:\Python26\lib\site-packages\django\db\backends\creation.py",
line 336, in create_test_db
call_command('syncdb', verbosity=verbosity, interactive=False)
  File "C:\Python26\lib\site-packages\django\core\management
\__init__.py", line 166, in call_command
return klass.execute(*args, **defaults)
  File "C:\Python26\lib\site-packages\django\core\management\base.py",
line 222, in execute
output = self.handle(*args, **options)
  File "C:\Python26\lib\site-packages\django\core\management\base.py",
line 351, in handle
return self.handle_noargs(**options)
  File "C:\Python26\lib\site-packages\django\core\management\commands
\syncdb.py", line 93, in handle_noargs
cursor.execute(statement)
  File "C:\Python26\lib\site-packages\django\db\backends\mysql
\base.py", line 84, in execute
return self.cursor.execute(query, args)
  File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 166,
in execute
self.errorhandler(self, exc, value)
  File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line
35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1005, "Can't create table
'test_myproject.#sql-710_139' (errno: 150)")


Table name #sql-710_139 doesn't make sense, so it's doesn't look to me
like something I could do wrong.

Has some of you an idea of what's going on here?

--
Tomasz Zieliński
http://pyconsultant.eu

--

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=.




Re: QuerySet Question

2009-11-12 Thread Tomasz Zieliński
On 12 Lis, 16:12, Chris <chrisbrett...@googlemail.com> wrote:
> Is there a way of getting a model function to access user details so
> that I can do a simple "if track.owned" in the template? Is there a
> better solution to doing it in the view? Is there something I have not
> thought of? What would be the "best practice" solution to this?
>

Just some quick ideas (after 10h of work, so watch out ;)):

1. You can write custom tag {%ifowned track request.user%}

2. You can try something less elegant:

{%for user in track.m2m_users.all%}
{%ifequal user request.user%}

{%endifequal%}
{%endfor%}

- but it's only good for small apps, as a temp solution.

--
Tomasz Zieliński
http://pyconsultant.eu

--

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=.




Re: Optimizing queries

2009-11-08 Thread Tomasz Zieliński

On 8 Lis, 18:06, Victor <psyco...@gmail.com> wrote:
> Hi,
>
>
> user_item_rel_set is a m2m relationship between the User and Item
> class.  For every item, I look back at its m2m relationship model and
> retrieve payment_amount.  The only problem is, select_related()
> doesn't grab the user_item_rel_set.all() when I query for the items
> (where items=Item.objects.select_related().all() ).  Is there anything
> I can do to speed this up? It's *very* slow.

I'm not sure what you're trying to do, but what about:

items_user = Item.objects.filter(user=u)
items_buyer = Item.objects.filter(buyer=u)

- and then do something with those lists?

--
Tomasz Zieliński
http://pyconsultant.eu


--~--~-~--~~~---~--~~
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: How to remove "" from text for email

2009-11-08 Thread Tomasz Zieliński



On 8 Lis, 21:41, zweb <traderash...@gmail.com> wrote:
> I have
>
> description|safe|striptags
>
> but description has some "" in addition to html tags. How do I
> strip that off?

There is 'cut' built-in filter. In never used it
but looking at its source code it looks to me
that it does what you want.

--
Tomasz Zieliński
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: DRY: max length not taken from Model.field when using ModelForm

2009-11-07 Thread Tomasz Zieliński

On 7 Lis, 18:25, fest <hell...@gmail.com> wrote:
> From my experience, max_length is not taken into account when you
> override model field in form field.

This is (and was, when I first time faced it) quite obvious for me .
If ModelForm was modifying overridden fields, the whole concept
of overriding would be useless.

On the other hand it would be nice if we could write something like:

first_name = forms.CharField(max_length=copy_from_model)

--
Tomasz Zieliński
http://pyconsultant.eu

--~--~-~--~~~---~--~~
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: token.split_contents() behavior

2009-11-07 Thread Tomasz Zieliński

On 7 Lis, 03:28, Tom von Schwerdtner <tomv...@gmail.com> wrote:

>
> Is that the intended behavior? It seems a bit wonky...
>

http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-the-compilation-function

"""
if not (format_string[0] == format_string[-1] and format_string[0] in
('"', "'")):
raise template.TemplateSyntaxError, "%r tag's argument should
be in quotes" % tag_name
"""

"""
The token.split_contents() method separates the arguments on spaces
while keeping quoted strings together. The more straightforward
token.contents.split() wouldn't be as robust, as it would naively
split on all spaces, including those within quoted strings. It's a
good idea to always use token.split_contents().
"""

So - yes, it is intended

--
Tomasz Zieliński
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: Feedback on Django1.1.1

2009-11-07 Thread Tomasz Zieliński

On 7 Lis, 09:03, Good Z <goodz...@yahoo.com> wrote:

>
> Any feedback on 1.1 for production software is appreciated.
>

I recently migrated quite big live service from 1.0.2 to 1.1.1
and I didn't observe even single migration-related problem.
It was probably the smoothest upgrade I had in a few years.
But I remember migrating from 0.9 to 1.0 and that wasn't as smooth
as 1.0->1.1.

--
Tomasz Zieliński
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: A simple database project

2009-11-07 Thread Tomasz Zieliński



On 7 Lis, 15:58, Zeynel <azeyn...@gmail.com> wrote:
> Hello,
>
> I am planning to build a demo prototype for a who-knows-who database
> for the legal profession. Database will consist of lawyer name, school
> and year graduated. Searching by lawyer name will return other lawyers
> graduated from same law school the same year. Can I build this in
> Django? How long would it take me to learn enough Django to build this
> myself?
>

Of course you can build this in Django, I think that going through
tutorial:

http://docs.djangoproject.com/en/dev/intro/tutorial01/

is enough to build it in no longer that a few days (learning
included),
even for pre-intermediate programmer.

--
Tomasz Zieliński
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: syncdb fails to update Not NULL property in PostgreSQL 8.4

2009-10-21 Thread Tomasz Zieliński


On 21 Paź, 19:20, "Thomas B. Higgins" 
wrote:
> Using the SVN trunk version of Django, I have observed that if a model
> IntegerField or FloatField is changed by adding "null=True" syncdb
> does not update the Not NULL property of the column using PostgeSQL
> 8.4. Is this correct behavior, or a bug? The two easy workarounds are
> (1) drop the table using pgAdmin III and follow with a syncdb creating
> a new table which will have the correct Not NULL status, or (2)
> manually change the Not Null property value for the column using
> pgAdmin III. Obviously the first method is a bit extreme.

There is also method (3) - use migration app, I suggest you take
a look at South: http://south.aeracode.org - it's very easy to pickup
up.

--
Tomasz Zielinski,
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: JOINs with Django ORM

2009-10-20 Thread Tomasz Zieliński



On 20 Paź, 08:37, "Michael P. Jung"  wrote:
> > I was unclear, but SQL should explain what I want to do - select
> > all ObjectRevision-s that are latest in Object-s that they belong to.
> > Moreover, I want to do this in with one ORM query, without resorting
> > to SQL or splitting the query too much.
>
> I'd go for a denormalized database:
>
> class Foo(models.Model):
>     latest_revision = models.OneToOneField('FooRevision',
>             related_name='latest_revision_for')
>     ...
>
> class FooRevision(models.Model):
>     foo = models.FogeignKey(Foo)
>     ...
>
> That way you can easily query Foo.objects.all().select_related() and be
> done. It'll be faster than your rather complex DB query and can be
> handled in the Django ORM. I'd say it's a win win situation.
>

I'm aware of this solution, in fact I was using it.
Unfortunately I had problems with deleting objects with this circular
dependency,
but maybe I was overlooking something (db we're using is MySQL 5).

Anyway, my case is much more complicated so I would have to
denormalize
more than just one model. Because of that, of because VIEWs + fake
models
are quick enough for what I'm doing (and has enough speed reserve for
the future),
I decided to go this path.

--
Tomasz Zielinski,
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: JOINs with Django ORM

2009-10-19 Thread Tomasz Zieliński

On 19 Paź, 20:21, Daniel Roseman  wrote:
>
> You can't do this in one query with Django's ORM.
>
> One way of doing it in two queries might be to get use .annotate() to
> add the max id of the related objectrevision for each revision, then
> get all those objectrevisions (untested):
>
>    objects = Object.objects.all().annotate(revision_id=Max
> ('objectrevision__id'))
>    objectrevisions = ObjectRevision.objects.filter(id__in=
> [o.revision_id for o in objects])
>

I found this solution, but we are talking about thousends of objects,
so SQL query would be really huge. I' tested it with MySQL Query
Browser
and passing ton of ids to `WHERE id IN (...)` clause was causing major
overhead
comparing to using JOIN.

Fortunately, in the mean time, I've found a nice solution using SQL
views:

http://wolfram.kriesing.de/blog/index.php/2007/django-nice-and-critical-article#comment-48425

This is not strictly a solution to the problem I asked, but it allows
to hide SQL under the floor
and just use Django ORM in everydays work.

Anyway, thank you for confirmation on this limitation, I wasn't sure
about it.

--
Tomasz Zielinski
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: JOINs with Django ORM

2009-10-19 Thread Tomasz Zieliński

On 19 Paź, 17:52, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Oct 19, 4:17 pm, Tomasz Zieliński
>
>
> It's not clear what you mean by 'all latest ObjectRevisions'. Do you
> mean all ObjectRevisions for a particular object? If so:
>     myobject.objectrevision_set.all()

I was unclear, but SQL should explain what I want to do - select
all ObjectRevision-s that are latest in Object-s that they belong to.
Moreover, I want to do this in with one ORM query, without resorting
to SQL or splitting the query too much.

--
Tomasz Zielinski
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



JOINs with Django ORM

2009-10-19 Thread Tomasz Zieliński

Say I have Object model, which has ObjectRevision-s (ObjectRevision
has ForeignKey to Object). I want to fetch from database all latest
ObjectRevision-s. In SQL I can do it like this:

SELECT r1.some_data
FROM objectrevision r1
LEFT OUTER JOIN objectrevision nr2
ON (r1.object_id = r2.object_id AND r1.id < r2.id)
WHERE r2.id IS NULL

What would be be the best way to do it with Django ORM?

--
Tomasz Zielinski
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: Django methodologies and best practices

2009-10-19 Thread Tomasz Zieliński



On 19 Paź, 12:00, bruno desthuilliers 
wrote:
> On 18 oct, 23:15, Mike Ramirez  wrote:
>
> Or write a custom migration script, or just fire your favorite db
> client and issue a couple SQL queries.
>
> > I tend to start with the models first and when I add a field, I just use 
> > alter
> > to update the table in place. This has a gotcha with NOT NULL though, if you
> > don't specify a default you'll end up with an error.  To bypass this error, 
> > I
> > usually don't add the NOT NULL constraint till after I've added the field 
> > and
> > updated the existing rows with the required data.
>
> > This may not be the best approach to it, but it works for me and is fast
> > enough and requires less prep time for using such tools as evolution and the
> > like (no need to install or learn them) and/or editting fixtures.
>
> +1

I was also migrating manually, but after I started using 
http://south.aeracode.org/
now I could not imagine going back to doing manual migrations.

--
Tomasz Zielinski
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: Django methodologies and best practices

2009-10-18 Thread Tomasz Zieliński


On 18 Paź, 15:48, bruno desthuilliers 
wrote:
>
> a first working implementation of my models (remember you can test
> your models from the interactive shell and/or python scripts).

Or write unit tests, which are more suited for testing than loose
bunch of scripts

--
Tomasz Zielinski,
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: Problem in installing database adapter.

2009-10-18 Thread Tomasz Zieliński

I don't remember how I installed it (mysqldb or python-mysqldb),
but assuming that this is the correct module, then it's possible
that it's for different Python version that you are actually using.

For example, default Python for Ubuntu 8 is, iirc, 2.5.2,
while you might be using 2.4 or 2.6 for your development.

If this is the case, then you can try easy_install for your version of
Python,
again iirc (writing out of my head), it could be as simple as
easy_install2.6 mysqldb

--
Tomasz Zielinski,
http://pyconsultant.eu


--~--~-~--~~~---~--~~
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: How to restrict True value to only one row in table column

2009-10-18 Thread Tomasz Zieliński

Maybe you can use something like this:

http://stackoverflow.com/questions/1346765/unique-constraint-that-allows-empty-values-in-mysql

This would probably mean converting is_master to:

is_master = models.BooleanField(null=True, blank=True, unique=True)

- and possibly overriding save to convert accidental False-s to None-
s.

Other solution would be to store somewhere (possibly in separate model
with single instance) separate value:

which_Thing_is_master

Just some quick ideas.

--
Tomasz Zielinski
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: Django SAAS projects

2009-10-18 Thread Tomasz Zieliński

There is also second issue to consider - single database
is a potential security threat (one customer might be able to access
data of second customer if you have a bug in your code).

--
Tomasz Zielinski,
http://pyconsultant.eu


--~--~-~--~~~---~--~~
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: Django methodologies and best practices

2009-10-18 Thread Tomasz Zieliński

It surely depends on your input. If you have detailed specification
of user interface, then writing URLconfs is probably more or less no-
brainer,
and also the design can often be quite obvious.

On the other hand, if you're starting in 'fluid' environment
and project doesn't have a direction, then you're forced to start
with one view and evolve design.

Re templates - it depends on whether you receive them from you
customer
or only know some general requirements and have to improvise until
some consensus
is reached.

So, if you ask me, then there is no single answer to your questions.
If you want to get more precise answer then you have to provide
some more insight into your problem.

--
Tomasz Zielinski
http://pyconsultant.eu

--~--~-~--~~~---~--~~
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: about django.core.mail.send_mail

2009-10-09 Thread Tomasz Zieliński



On 9 Paź, 05:15, li kai  wrote:
> Can I send email using others' mail account following these steps?
>
> 1. I fill my own mail account and password in settings.py.
>
> 2. When using "send_mail(subject, message, sender, recipients)", I set
> sender to  a different mail account.

This depends on your email server settings - it can prohibit sending
emails
from other addresses. If this is the case and you don't have control
over it,
then you can try creating alias for you account email and sending
emails
from that alias (at least it is something that works for me one one
hosting
with 'strict' policy on sending emails).

--
Tomasz Zielinski
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: Automatic primary keys at model inheritance

2009-10-09 Thread Tomasz Zieliński

>
> the primary key counters for Restaurant and Bar classes are separated, which
> causes me troubles, because I want a Place to be Restaurant or Bar not both.
>

I'm not sure if this is what you need, but take a look here:

http://docs.djangoproject.com/en/dev/topics/db/models/#id8

--
Tomasz Zielinski
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: "Lost" sessions

2009-07-25 Thread Tomasz Zieliński

In case someone suffers from this -I found the problem:
http://code.djangoproject.com/ticket/11555

--
Tomasz Zieliński
http://pyconsultant.eu

--~--~-~--~~~---~--~~
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: "Lost" sessions

2009-07-25 Thread Tomasz Zieliński

One more thing - out of sudden it turns out that session can be "lost"
even if no external redirect is involved.
So basically first request, without any session cookie set, seems to
have some dummy session id,
because only subsequent sessions ids survive.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



"Lost" sessions

2009-07-25 Thread Tomasz Zieliński

Hello!

I have a problem with sessions being lost under some conditions
(not sure what these conditions are). Steps to reproduce this:

http://info-site.com/, click link "Best holidays!" which redirects to:
http://my-site.com/, session A is created by Django, then click
internal link '/more-info/'
http://my-site.com/more-info/, session A is lost, session B is created
and it survives next clicks

This happens only for some IPs (or computers, but I tried it myself on
two computers and 4 browsers
sharing the same IP and it's consistent on all of them - session A is
lost, so it seems like something
connected to IP)

Is this some known issue with Django or maybe internet gateways(?) -
or I have a bug myself?
 (I'm not messing with Django session code in any way)

--
Tomasz Zieliński,
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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: "Lost" sessions

2009-07-25 Thread Tomasz Zieliński

I've just noticed that my fake URLs point to existing sites
--~--~-~--~~~---~--~~
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: Django, MySQL - bug?

2009-07-20 Thread Tomasz Zieliński

I tried this:

import MySQLdb
db = MySQLdb.connect(...)
c = db.cursor()
c.execute("create table mtest (pk int not null auto_increment primary
key, s varchar(5)) type=InnoDB")

print c.execute("insert into mtest values (null,'12345')")
print c.messages
print c.lastrowid

print c.execute("insert into mtest values (null,'123456789')")
print c.messages
print c.lastrowid

And I got this:

1
[]
21

1
[(, ('Warning', 1265L, "Data
truncated for column 's' at row 1"))]
22

So it seems to my MySQLdb actually returns primary key for INSERT that
causes Warning.

One thing that is different here from Django scenario is that Warning
is not being thrown,
does someone know how to turn on raising Warning exceptions in
MySQLdb?

--
Tomasz Zieliński
http://pyconsultant.eu
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



  1   2   >