Re: Django model version control

2008-10-04 Thread Bas van Oostveen


That is exactly what i did for a project :)

When you register a model for versioning, automagicly a new model is
created which the original model + an 'version-control' abstract base model
to add things like version numbers, datetimestamps, methods to diff between
versions etc. Also all unique restricted are removed from the 'history'
model to not create constraints problems.

So you can stuff like:
 FooHistory.objects.get(rev=42)
 FooHistory.objects.latest().diff(fooInstance)
 FooHistory.objects.latest().revert()

Ofcourse now you need to migrate two tables instead of one, on a schema
change, but in most cases that's just repeating the migration.

This approach has worked very well for me. Though i havn't used it any
'big' projects.

Bas

On Fri, 3 Oct 2008 17:29:34 +0300, Erik Allik <[EMAIL PROTECTED]> wrote:
> 
> What if, for each model under version control, you'd create an  
> identical table (except the ID field would be a foreign key, not a  
> primary one). Any time a migration is run on that model, the same  
> migration could be run on the "twin" table, too.
> 
> Erik
> 
> On 02.10.2008, at 18:34, David Hall wrote:
> 
>>
>> That is a problem, to be sure, and I'm not sure if a reasonable  
>> solution
>> exists.
>>
>> As it stands, Django is currently lacking an automated rollback/ 
>> recovery
>> for models.  The fullhistory branch tried to address this lack, but
>> seems to have been abandoned for the time being.
>>
>> django-reversions implements this rollback/recovery facility in a way
>> that aims to be easy to integrate with existing projects.  It improves
>> upon the current fullhistory implementation by:
>>
>>  - Using the serialization framework instead of pickle.
>>  - Allowing groups of changes to be grouped into revisions.
>>  - Integration with newforms-admin.
>>
>> Changes to database schemas will indeed break the rollback facility.
>> Given the mind-boggling vastness of possible schema migrations, I
>> honestly would not know how to begin to implement such a feature!
>>

>> Nevertheless, I hope that django-reversions remains a useful tool.
>>
>> David.
>>
>> Bas van Oostveen wrote:
>>> But your schema's will most likely change over time. And sometimes in
>>> significant ways which do not have a likely default; e.g. splitting a
>>> full_name field into a first_name and last_name field or visa-versa.
>>>
>>> Now after applying this change to the database, how will
>>> django-reversions work when you want to undo and go back to an  
>>> earlier
>>> version of a record in this table ? (which didn't have this change)
>>>
>>> The fields in the database/model now do not match against the  
>>> serialized
>>> copy right ?
>>>
>>> Bas
>>>
>>>
>>> On Wed, 2008-10-01 at 16:52 +0100, David Hall wrote:
 This discussion has been moved from django-developers.

 To answer a pending question:  This application is for tracking  
 versions
 of data, not performing database schema migrations.  Thus:

   - django-evolution concerns itself with maintaining versions of
 database schemas.

   - django-reversion deals with maintaining versions of the model  
 data.

 It does not integrate with subversion.  Instead, it uses the django
 serialization framework to store serialized models in a special  
 database
 table.

 David.

 David Hall wrote:
> I've just released an open-source version control application for
> Django.  It is available for download from Google code.
>
> http://code.google.com/p/django-reversion/
>
> Features include:
>
>  - Roll back to any point in a model's history - an unlimited undo
> facility!
>  - Recover deleted models - never lose data again!
>  - Admin integration for maximum usability.
>  - Group related changes into revisions that can be rolled back  
> in a
> single transaction.
>  - Automatically save a new version whenever your model changes  
> using
> Django's flexible signalling framework.
>  - Automate your revision management with easy-to-use middleware.
>
> It can be easily added to your existing Django project with an
> absolute minimum of code changes.
>
> It's so far been previewed by a half dozen developers, with good
> feedback.  I'd appreciate any comments / suggestions you may have  
> to
> offer.
>
>>>
>>>

>>
>> -- 
>>  David Hall
>>  Technical Lead
>>  Etianen.com
>>  Tel: 07896 106290
>>
>>  Email[EMAIL PROTECTED]
>>  Web  www.etianen.com
>> ---
>>  Ask for help at [EMAIL PROTECTED]
>>  Etianen.com is a small, professional web development agency that
>>  specialises in fast-paced, creative development.
>> - enlightened website development -
>>
>> >
> 
> 
> 

--~--~-~--~~~---~--~~
You received this message because you are subscri

Re: Django Hangman

2008-10-04 Thread Ovnicraft
2008/10/2 chatchai <[EMAIL PROTECTED]>

>
> Hi all,
>
> I have built Hangman game using Django. You can see it at
> http://feedfrog.net/app/hangman
>
> If anybody interest in its code, please contact me.
>
> Enjoy :)
>
> Chatchai
> >
>

i get it now and review thanks for the contribution, Free as in Freedom !
-- 
[b]question = (to) ? be : !be; .[/b]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Help with login

2008-10-04 Thread KillaBee



On Oct 3, 5:08 am, hcsturix74 <[EMAIL PROTECTED]> wrote:
> HI, I've upgraded my site to django 1.0 from 0.96 and  I've installed
> "user registration" app from googlecode.
> My homepage is a flatpage but I want to insert a login form (just a
> form with username and password)
> How could I do that? Can you suggest how to do it?
> User Registration app uses django.contrib.auth.login but the "form"
> variable (exported in login method) is not visible in flatpage context
> (of course).
> Should I use a custom tag in registration app  and use it in my
> flatpage (Homepage)?
> And, if yes how to manage "request" parameter in this custom tag?
> All examples I've seen, use a dedicated page for login (tipically /
> accounts/login/), I mean a dedicated view.
> I hope my question is clear. Sorry if it's a silly question, but I'm a
> django newbie.

I am having a hard time with login also.  I looked at the admin login
that came with 1.0. My thing is the next of the html, and getting user
info to show.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: SQL: Migration How To?

2008-10-04 Thread Benjamin Buch

Thanks James and Russel for your replies.

Am 04.10.2008 um 07:22 schrieb Russell Keith-Magee:
>
> On Sat, Oct 4, 2008 at 12:36 PM, Benjamin Buch <[EMAIL PROTECTED]>  
> wrote:
>>
>> Is there somewhere a place in the documentation where SQL migration
>> strategies are explained a little?
>> I think I remember a paragraph in the pre-1.0-documentation that
>> described what you have to do with your database when you'd like to
>> add a column to your model, but I can't find it anymore.
>
> This isn't the sort of thing that Django can document easily (and I
> certainly can't recall it ever being mentioned in the Django docs).
> The problem is that is isn't as simple as 'the SQL statement you need
> to run' - every database does it quite differently.

Yes, documenting the whole thing would not be easy, you're absolutely  
right.

But some hints on strategy would be very helpful I guess.
Not in the sense of written SQL statements for every database, and not  
for every problem which could propably emerge when the models evolve.
But I think there are some common patterns - like adding a field to a  
model - that could be described in a way that would be sufficient as  
an entry point to learning SQL.
When I remember it right, then the paragraph I mentioned (I think it  
was in the tutorial...) was something like
- alter your model
- use manage.py sql altered_app to output the SQL statements you would  
use to create the table
- alter the table along the lines of those statements

At least this was a hint what to do...

Or possibly another hint could be something like
- dump the database tables you want to alter
- put in the changes manually
- delete the (now old) tables in your db
- import the altered dump

(I don't know if this works, but I will try...)

So I'm not looking for a full-feldged documentation, just for some  
hints on strategy or some examples as a starting point to dive in  
deeper.

>> Working with django for some weeks now, I find it quite common to  
>> want
>> to add or modify a column after the db is synced and some (valuable)
>> data is put in.
>> Since it will propably take some time that the three great migration
>> apps will merge(?) somehow and find their way into trunk (at least
>> that's the way I understood it when watching the video from django
>> con...),
>> I dicided to do migration by hand.
>
> Merging Django Evolution, South and dmigrations is certainly something
> that the three of us have discussed. We hope to be able to make some
> public announcements about this in the near future.

I'm looking forward to this! I liked the talk on django con...

> In the meantime, any of the three migration projects are usable as-is.
>
>> I don't know SQL, and I find it quite hard to search for  
>> documentation
>> (although there is good documentation about SQL out there...), think
>> about migration strategies and tinker with differences between  
>> sqlite3
>> and mysql.
>> So is there anywhere a short explanation of SQL from a django point  
>> of
>> view out there?
>
> Your best source of documentation will be the SQL manual for your
> database of choice, and/or the tutorials around the web for the same.
> There's almost nothing Django specific about migrations at the SQL
> level, other than knowing what you need your database to look like at
> the end of the process (which you can find out using ./manage sqlall).

As James said, I should stop and learn some SQL.
Thanks for the tip on manage.py, it is quite useful.
At least it shows how SQL statements should look...

-benjamin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Questions about HttpResponseRedirect and reverse

2008-10-04 Thread Malcolm Tredinnick


On Fri, 2008-10-03 at 13:29 -0400, Steve Holden wrote:
> Alexis Bellido wrote:
> > Cool, thanks for the confirmation. I'm still devouring all the
> > documentation, a couple of books and practicing a lot on Django :)
> >   
> One of the things I find tricksiest about learning new Django code is
> that the connections between the URLs and the views can often turn out
> to be a maze of twisty little passages, all alike. It's difficult (for
> me, anyway - maybe there's some obvious technique I have overlooked) to
> trace which pieces of code and which URLs are associated.

Hmm... this is getting off-topic a bit for this thread, but can you
elaborate a bit more on what you mean here? I can't say this was
something that every seemed tricky to me with Django, but I know
different people learn and think differently, so it would be interesting
to hear where there hidden shoals might be.

It feels like it should be as simple as being a reg-exp pattern that
captures some parameters and calls a view passing in those parameters
and possible some extra ones. You can also give each pattern a name.

I'm not mocking here. I'd like to hear how this can be hard so that I
can at least experiment with some alternative explanations in the future
when talking to people.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Q about a ticket and merging into svn

2008-10-04 Thread Malcolm Tredinnick


On Fri, 2008-10-03 at 19:51 +0800, Russell Keith-Magee wrote:
[...]
> I wouldn't pin your hopes on the patch making it into trunk. I simply
> can't give you any indication of when it will happen. I might happen
> next week, it might happen next year. Until it happens, we won't know.
> I can tell you that this isn't particular ticket isn't on my personal
> to-do list.

It's on my list, but it's after some other items that will probably
change the approach. We need to get date output formats that work
"naturally" in a locale-aware environment working first, then we can
address more individual customisations. The former is something I'm
working on (along with 17 other high priority things in my spare time)
for Django core at the moment. I'm not going to do anything with that
ticket until then, but it's likely to be at least progressed somewhat
before 1.1.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: python-ldap + Apache causing errors

2008-10-04 Thread Graham Dumpleton

Arrgh, not that issue. Ie.,

__THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALI
TY___YOU_MUST_EXEC__()

I have seen this before and we got no where in working it out except
that some special MacOS X  framework and/or function was being used
that had some restrictions on it.

If you create a separate discussion on mod_wsgi list, will at least
sit there to remind me and can do some more research on it again.

Graham


On Oct 4, 8:29 am, Jashugan <[EMAIL PROTECTED]> wrote:
> On Sep 24, 5:05 pm, Graham Dumpleton <[EMAIL PROTECTED]>
> wrote:
>
> > > > To really get to the problem, you may need to start up Apache in
> > > > single process mode and run it in a debugger. For details see:
>
> > > >http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Debugging_C...
>
> So I tried mod_wsgi, but ran into the same problems as with
> mod_python. Namely:
>
> The process has forked and you cannot use this CoreFoundation
> functionality safely. You MUST exec().
> Break on
> __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALI 
> TY___YOU_MUST_EXEC__()
> to debug.
> ... snip 50 lines of the same error above repeating itself ...
> [Fri Oct 03 14:58:16 2008] [error] [client 10.10.6.1] Premature end of
> script headers: conf.wsgi
> [Fri Oct 03 14:58:17 2008] [notice] child pid 25258 exit signal Trace/
> BPT trap (5)
>
> Here is the configuration I used:
>
> WSGIDaemonProcess site-1 user=www group=www processes=5 threads=1
> WSGIProcessGroup site-1
>
> WSGIScriptAlias /ri /opt/local/var/www/django/ri/lib/apache/conf.wsgi
>
> 
>     Order deny,allow
>     Allow from all
> 
>
> Here is the output of httpd -V:
>
> Server version: Apache/2.2.8 (Unix)
> Server built:   Apr 22 2008 14:47:50
> Server's Module Magic Number: 20051115:11
> Server loaded:  APR 1.3.2, APR-Util 1.3.2
> Compiled using: APR 1.2.12, APR-Util 1.2.12
> Architecture:   32-bit
> Server MPM:     Prefork
>   threaded:     no
>     forked:     yes (variable process count)
> Server compiled with
>  -D APACHE_MPM_DIR="server/mpm/prefork"
>  -D APR_HAS_MMAP
>  -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
>  -D APR_USE_SYSVSEM_SERIALIZE
>  -D APR_USE_PTHREAD_SERIALIZE
>  -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
>  -D APR_HAS_OTHER_CHILD
>  -D AP_HAVE_RELIABLE_PIPED_LOGS
>  -D DYNAMIC_MODULE_LIMIT=128
>  -D HTTPD_ROOT="/opt/local/apache2"
>  -D SUEXEC_BIN="/opt/local/apache2/bin/suexec"
>  -D DEFAULT_PIDLOG="logs/httpd.pid"
>  -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
>  -D DEFAULT_LOCKFILE="logs/accept.lock"
>  -D DEFAULT_ERRORLOG="logs/error_log"
>  -D AP_TYPES_CONFIG_FILE="conf/mime.types"
>  -D SERVER_CONFIG_FILE="conf/httpd.conf"
>
> The solution we are using right now is a custom HTTP job server that
> will receive function requests and process them. However, I would
> rather get the solution working in Apache if possible in order to keep
> things simple.
>
> Also, Graham, do you want me to create a new thread in the mod_wsgi
> google mailing list?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Mod_python

2008-10-04 Thread Graham Dumpleton



On Oct 4, 2:07 am, djandrow <[EMAIL PROTECTED]> wrote:
> I just bought a new laptop and want to install mod_python, is there a
> version which is compatible with Python 2.6, I tried the 2.5 version
> but it wouldn't let me install that with 2.6. If there isn't a 2.5
> version what would people recommend I do? Thanks.

I have seen no reports of mod_python not working with Python 2.6, but
also haven't see any reports of it working with Python 2.6 either.

If you you are only wanting to host Django, do understand that
mod_wsgi works with Python 2.6.

The version of mod_wsgi in the repository trunk even supports
directive which achieves same thing as Python 2.6 command line option
'-3', used for preparing code for migration to Python 3.0.

If you have tried to compile mod_python from source with Python 2.6,
and it didn't wort, you may want to post what the problem was to
mod_python mailing list. See mod_python site for details of the list.

Graham
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: database program

2008-10-04 Thread Tim Chase

> But... The tutorials I've been reading online all recommend
> PostgreSQL.   I don't care, I'll go that route, but the online server
> I am currently using only offers MySQL. Are these two engines
> compatible, or am I going to have to go against what the tutorial
> advises and intall MySQL on my machine?

If you stick to Django's ORM, you should be pretty safe as it 
abstracts away many of the DB-specific portions.  Areas to watch:

1) if you use any calls to .extra() that use DB-specific 
functionality

2) possibly some GIS-related functionality (django.contrib.gis) 
may be limited if you don't run PostgreSQL or Oracle.  I haven't 
deep-dived into that code, but I know it does exploit some of the 
benefits that pg uses

3) if you use a raw connection.cursor to execute custom SQL, 
you're walking in territory that may not port from one DB to another

4) if you use any sort of initial-sql functionality that does 
DB-specific things.

You'll notice the common theme of "if you do something DB 
specific, $PROBLEM may occur (or may require special attention to 
making it DB-portable)" which is the gist of the whole thing. :)

-tim



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: SQL: Migration How To?

2008-10-04 Thread James Bennett

On Fri, Oct 3, 2008 at 11:36 PM, Benjamin Buch <[EMAIL PROTECTED]> wrote:
> Is there somewhere a place in the documentation where SQL migration
> strategies are explained a little?

No. For the moment, the only "official", if it can be called that, way
to do this is via SQL's ALTER TABLE statement. There are several
third-party projects attempting to make this easier, but none of them
are part of Django.

> I don't know SQL

As an aside, this is probably an indicator that you should stop and
learn SQL. Trying to write applications which are backed by a
SQL-based DB, when you don't understand the language of that DB, will
only end in tears.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django model version control

2008-10-04 Thread David Hall

I did consider such an approach, but this runs into a fair amount 
confusion for things like model inheritance.  Also, it would result in 
vast quantities of database tables being created.

Likewise, custom fields would have to be treated carefully, as would 
unique fields.  Also if you have any ManyToMany relationships, these 
linking tables would also have to be created.

None of these are insurmountable problems, but they would result in a 
much more heavyweight application.  Currently, django-reversion is a 
very small app indeed, and will only contribute one extra database table 
to your schema.  This makes it very easy to integrate with existing 
projects.

David.


Bas van Oostveen wrote:
> 
> That is exactly what i did for a project :)
> 
> When you register a model for versioning, automagicly a new model is
> created which the original model + an 'version-control' abstract base model
> to add things like version numbers, datetimestamps, methods to diff between
> versions etc. Also all unique restricted are removed from the 'history'
> model to not create constraints problems.
> 
> So you can stuff like:
>  FooHistory.objects.get(rev=42)
>  FooHistory.objects.latest().diff(fooInstance)
>  FooHistory.objects.latest().revert()
> 
> Ofcourse now you need to migrate two tables instead of one, on a schema
> change, but in most cases that's just repeating the migration.
> 
> This approach has worked very well for me. Though i havn't used it any
> 'big' projects.
> 
> Bas
> 
> On Fri, 3 Oct 2008 17:29:34 +0300, Erik Allik <[EMAIL PROTECTED]> wrote:
>> What if, for each model under version control, you'd create an  
>> identical table (except the ID field would be a foreign key, not a  
>> primary one). Any time a migration is run on that model, the same  
>> migration could be run on the "twin" table, too.
>>
>> Erik
>>
>> On 02.10.2008, at 18:34, David Hall wrote:
>>
>>> That is a problem, to be sure, and I'm not sure if a reasonable  
>>> solution
>>> exists.
>>>
>>> As it stands, Django is currently lacking an automated rollback/ 
>>> recovery
>>> for models.  The fullhistory branch tried to address this lack, but
>>> seems to have been abandoned for the time being.
>>>
>>> django-reversions implements this rollback/recovery facility in a way
>>> that aims to be easy to integrate with existing projects.  It improves
>>> upon the current fullhistory implementation by:
>>>
>>>  - Using the serialization framework instead of pickle.
>>>  - Allowing groups of changes to be grouped into revisions.
>>>  - Integration with newforms-admin.
>>>
>>> Changes to database schemas will indeed break the rollback facility.
>>> Given the mind-boggling vastness of possible schema migrations, I
>>> honestly would not know how to begin to implement such a feature!
>>>
> 
>>> Nevertheless, I hope that django-reversions remains a useful tool.
>>>
>>> David.
>>>
>>> Bas van Oostveen wrote:
 But your schema's will most likely change over time. And sometimes in
 significant ways which do not have a likely default; e.g. splitting a
 full_name field into a first_name and last_name field or visa-versa.

 Now after applying this change to the database, how will
 django-reversions work when you want to undo and go back to an  
 earlier
 version of a record in this table ? (which didn't have this change)

 The fields in the database/model now do not match against the  
 serialized
 copy right ?

 Bas


 On Wed, 2008-10-01 at 16:52 +0100, David Hall wrote:
> This discussion has been moved from django-developers.
>
> To answer a pending question:  This application is for tracking  
> versions
> of data, not performing database schema migrations.  Thus:
>
>   - django-evolution concerns itself with maintaining versions of
> database schemas.
>
>   - django-reversion deals with maintaining versions of the model  
> data.
>
> It does not integrate with subversion.  Instead, it uses the django
> serialization framework to store serialized models in a special  
> database
> table.
>
> David.
>
> David Hall wrote:
>> I've just released an open-source version control application for
>> Django.  It is available for download from Google code.
>>
>> http://code.google.com/p/django-reversion/
>>
>> Features include:
>>
>>  - Roll back to any point in a model's history - an unlimited undo
>> facility!
>>  - Recover deleted models - never lose data again!
>>  - Admin integration for maximum usability.
>>  - Group related changes into revisions that can be rolled back  
>> in a
>> single transaction.
>>  - Automatically save a new version whenever your model changes  
>> using
>> Django's flexible signalling framework.
>>  - Automate your revision management with easy-to-use middleware.
>>
>> It can be easily added to y

Re: Django model version control

2008-10-04 Thread David Hall

I've created a Google group for discussing possible improvements to the 
django-reversion project.  The group is called 'django-reversion', and 
is a good place to let your views be heard about enhancements to the system.

At some point I would like to put the project forward as a candidate for 
the currently-inactive fullhistory branch.  As such, your feedback and 
suggestions are vital to making this application as bombproof as possible.

David.

David Hall wrote:
> I've just released an open-source version control application for
> Django.  It is available for download from Google code.
> 
> http://code.google.com/p/django-reversion/
> 
> Features include:
> 
>   - Roll back to any point in a model's history - an unlimited undo
> facility!
>   - Recover deleted models - never lose data again!
>   - Admin integration for maximum usability.
>   - Group related changes into revisions that can be rolled back in a
> single transaction.
>   - Automatically save a new version whenever your model changes using
> Django's flexible signalling framework.
>   - Automate your revision management with easy-to-use middleware.
> 
> It can be easily added to your existing Django project with an
> absolute minimum of code changes.
> 
> It's so far been previewed by a half dozen developers, with good
> feedback.  I'd appreciate any comments / suggestions you may have to
> offer.
> 
> > 

-- 
  David Hall
  Technical Lead
  Etianen.com
  Tel: 07896 106290

  Email[EMAIL PROTECTED]
  Web  www.etianen.com
---
  Ask for help at [EMAIL PROTECTED]
  Etianen.com is a small, professional web development agency that
  specialises in fast-paced, creative development.
- enlightened website development -

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Access logged in user in models?

2008-10-04 Thread Benjamin Buch

It sounds like a strange question, but I'll ask it...

Is it possible to access the currently logged in user in a model?

This question is related to the following problem:
I have the models 'expense' and 'category' to keep track of my monthly  
expenses:

class Category(models.Model):
 category = models.CharField(max_length=100)
 slug = models.CharField(max_length=100)

class Expense(models.Model):
 category = models.ForeignKey(Category)
 date = models.DateField(default=datetime.date.today)
 description = models.TextField(blank=True)
 expense = models.FloatField()
 user = models.ForeignKey(User)

I'd now like to have a page where a logged in user can see his  
expenses for the actual month in the following way:

Category1:
expense1:   3.5
expense2:   3.5
total:  7.0

Category2:
expense1:   2
expense2:   3
total:  5

So I have to limit the query set by user and date (actual month), sort  
them somehow into the categories and sum up all expenses within one  
category.
I first tried to solve this problem in the template.
I queried for expenses and limited it by user and date like this:
expenses = Expense.objects.filter(user__username =  
user.username).filter(date__month = today.month).order_by('category')
Then I did this in the template:
{% if expenses %}

{% for expense in expenses %}
{% ifchanged %}{{ expense.category }}{% endifchanged  
%}

{{ expense.date }}
{{ expense.expense }}

{% endfor %}

{% endif %}
But as you can see there's no sum at the and, and I couldn't think of  
a way to do this.

Second attempt was to do it from within the model.
I came up with the following methods, attached to the model 'Category':

def get_monthly_expenses(self):
 expenses = Expense.objects.filter(date__month =  
datetime.date.today().month)
 return expenses

def get_monthly_total(self):
 monthly_total = 0.0
 expenses = self.get_monthly_expenses()
 for expense in expenses:
 monthly_total += expense.expense
 return monthly_total

I would then pass Category.objects.all() to the template.
The problem here is that I have no possibility to filter the expenses  
by logged in user beause I can't access the user from within the model.

Accessing the user from within the model seems somehow like a bad  
idea, but I can't see an other way to do this.

-benjamin


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Access logged in user in models?

2008-10-04 Thread Benjamin Buch

If I would do this in the view, I couldn't do something like this in  
the template:

{% for category in categories %}
{% for expense in category.get_monthly_expenses %}
...
{% endfor %}
{% endfor %}

If I do it in the view, the only way I can think of it could be  
accomplished by stuffing categories in dictionaries, appending the  
expenses...
Is this normal to do so?

But thanks anyway!
-benjamin

Am 04.10.2008 um 17:52 schrieb Ulises:

>
>> Accessing the user from within the model seems somehow like a bad
>> idea, but I can't see an other way to do this.
>
> How about doing it in a view where you have access to the user object?
> I reckon this is the type of stuff you normally do in views?
>
> U


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Access logged in user in models?

2008-10-04 Thread Ulises

> If I would do this in the view, I couldn't do something like this in
> the template:
>
> {% for category in categories %}
> {% for expense in category.get_monthly_expenses %}
> ...
> {% endfor %}
> {% endfor %}
>
> If I do it in the view, the only way I can think of it could be
> accomplished by stuffing categories in dictionaries, appending the
> expenses...
> Is this normal to do so?

You could still traverse a path along the lines of user -> expenses ->
categories which would let you skip those categories in which a
particular user hasn't incurred in expenses.

Unless I got you completely wrong, do you want to display only the
user's expenses and still display the grand total or is the total
displayed only the sum of the user's expenses?

Anyway, I still think that the heavy lifting should be done in a view
and that the template should be in charge of just displaying what has
been sent to it.

U

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Access logged in user in models?

2008-10-04 Thread Vovk D
2008/10/4, Benjamin Buch <[EMAIL PROTECTED]>:
>
>
> Category1:
> expense1:   3.5
> expense2:   3.5
> total:  7.0
>
> Category2:
> expense1:   2
> expense2:   3
> total:  5


First, i think smth like sum you can do easy with JavaScript on the
client-side, if cant do it on the server-side.
Second, logic like aggregation you must do in the View.
Third, it's a bad idea to do smth like this in a Model :)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Access logged in user in models?

2008-10-04 Thread Benjamin Buch

Am 04.10.2008 um 18:53 schrieb Vovk D:

>
>
> 2008/10/4, Benjamin Buch <[EMAIL PROTECTED]>:
>
> Category1:
> expense1:   3.5
> expense2:   3.5
> total:  7.0
>
> Category2:
> expense1:   2
> expense2:   3
> total:  5
>
> First, i think smth like sum you can do easy with JavaScript on the  
> client-side, if cant do it on the server-side.
> Second, logic like aggregation you must do in the View.
> Third, it's a bad idea to do smth like this in a Model :)

Na, I think this has to work without JavaScript.
But you are right, that's nothing for the model and should be handled  
in the view.
-benjamin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Access logged in user in models?

2008-10-04 Thread Ulises

> Accessing the user from within the model seems somehow like a bad
> idea, but I can't see an other way to do this.

How about doing it in a view where you have access to the user object?
I reckon this is the type of stuff you normally do in views?

U

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: mptt + contrib.comments?

2008-10-04 Thread Jonathan Nelson

I'm actually rolling my own threaded comments system using an MPTT
algorithm.  Contrib.comments and the django-mptt aren't a really good
fit for what I need.

It's taken me a while to get my head around the concept of traversing
the tree using the comment.left and comment.right values, but after
you understand it, it really seems to work well.

I'll try and put some code up on Google code when I get mine
finished.

I've found this article to be very helpful:
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

And, I've found this book to be invaluable:
http://www.amazon.com/Hierarchies-Smarties-Kaufmann-Management-Systems/dp/1558609202/ref=sr_1_5?ie=UTF8&s=books&qid=1223136111&sr=8-5

J.




On Oct 1, 2:10 pm, "Chris Stromberger" <[EMAIL PROTECTED]>
wrote:
> If I can get something working, I'll share!  Still fiddling around with it.
>
> On Wed, Oct 1, 2008 at 2:48 PM, john Moylan <[EMAIL PROTECTED]> wrote:
> > Hi Chris,
>
> > I'd love to see your finished code - if you can/want to share?
>
> > J
>
> > 2008/9/30 Chris Stromberger <[EMAIL PROTECTED]>
>
> > OK, nevermind on the admin page issue.  Was being caused
> >> by TEMPLATE_STRING_IF_INVALID being set to something other than ''.
> >> Would still love to see an example of contrib.comments + mptt!
>
> >> Thanks,
> >> Chris
>
> >> On Tue, Sep 30, 2008 at 4:25 PM, Chris Stromberger <
> >> [EMAIL PROTECTED]> wrote:
>
> >>> One specific issue I am having is that the admin screen for the Comment
> >>> model is not "synched up" with the data.  The admin list screen has a 
> >>> table
> >>> of field names, and the columns do not match the data--the data is 
> >>> shifted.
> >>>  So for example, the "Is public" column is displaying the IP address.  
> >>> Etc.
> >>>  Any ideas on what would cause this?  Mptt adds some fields to your model
> >>> dynamically, so wondering if this is somehow related.
> >>> Any tips appreciated.
>
> >>> Thanks,
> >>> Chris
>
> >>> On Tue, Sep 30, 2008 at 2:31 PM, Chris Stromberger <
> >>> [EMAIL PROTECTED]> wrote:
>
>  I'm trying to use mptt with contrib.commments and am not having much
>  luck.  Basically would like to allow nested comments.  Pretty new to 
>  Django,
>  so that is contributing to the problem.  Would love to see a simple
>  example/summary of what needs to change in contrib.comments to 
>  incorporate
>  mptt.
>  Thanks,
>  Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Name of button pressed not in request.POST

2008-10-04 Thread ydjango

I do not see the name of submit button in request.POST. it has all
other form fields

 if request.POST.has_key('save'):
 does not work too

Where can I find which button was pressed.



various fields...
 
other input buttons

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Q about a ticket and merging into svn

2008-10-04 Thread Gerard Petersen

Russel,

Thanx for your elaborate feedback. I'm indeed going to keep the widget code in 
a file within my own app for now. It's very workable this way, and I still have 
lots of other Django code to discover.

@Malcolm: I'd love to help but being a sysadmin and not a diehard developer, I 
can not offer more then testing and or writing docs.

Thanx again guys!

Regards,

Gerard.





Russell Keith-Magee wrote:
> On Fri, Oct 3, 2008 at 5:13 PM, Gerard Petersen <[EMAIL PROTECTED]> wrote:
>> I examined the svn tree and the patches. It seems that the diffs are for the 
>> widget.py file under 'newforms', but this directory does not exist in the 
>> svn tree. I've tried appending the widget classes from the ticket to:
>>
>> /usr/lib/python2.5/site-packages/django_src/django/forms/widgets.py
>>
>> I then end up in an 'import galore', that results in modifying files in the 
>> app and the django source tree in more places then seems healthy. Also 
>> ending up changing referencing, e.g. adding the extra 'widgets.' like this 
>> widget=widgets.DateFormattedTextInput() for instance.
>>
>> Then the best scenario I got without errors was a form.as_table that dit not 
>> generate a form. And the funny thing is everything does work when testing in 
>> './manage.py shell'
>>
>> Besides all that, the actual way that really works, was to simply add a 
>> 'datetimewidgets.py' with the classes to my app and import it.
>>
>> Since I would like to have it in the source tree properly ...
>>
>> Is the aformentionted widgets.py the right file (couldn't find that in the 
>> ticket) to place the new classes?
>> Should this sysadmin stay with the simple solution ... :-) and not put it in 
>> the source tree?
>> Is there (besides the source code ... ;-) any reading in regards to Django 
>> how this is setup?
> 
> You have correctly identified the right file. The django/newforms
> package was renamed to django/forms in the final days leading to the
> v1.0 release, but other than this rename, there weren't any major
> changes. widgets.py in the old directory corresponds to widgets.py in
> the new directory. As a result of the rename, the patch won't apply
> completely cleanly. This means there will be a little effort required
> to update the patch for a post v1.0 source tree.
> 
> As for the 'right way' to do this - that's entirely up to you and how
> comfortable you are with the tools required.
> 
> Personally - I have no problems running a heavily patched version of
> Django - but then, I'm a core developer who knows the internals of
> Django and is very comfortable with the git/svn/diff/patch tool set.
> If you're not as comfortable with these tools, and/or you'd rather
> just use a vanilla checkout, then you might want to look at
> alternative approaches.
> 
> I wouldn't pin your hopes on the patch making it into trunk. I simply
> can't give you any indication of when it will happen. I might happen
> next week, it might happen next year. Until it happens, we won't know.
> I can tell you that this isn't particular ticket isn't on my personal
> to-do list.
> 
> A better approach from your perspective may be to step completely out
> of the Django tree itself. Django widgets are not _required_ to be in
> newforms/widgets.py (or forms/widgets.py) - they are normal Django
> code, and as long as you can import the code, they can live anywhere
> you want. You may find that it is easier to create your own
> 'gerard_widgets.py' in your own project, put the modified widgets in
> that packaged, and reference those widgets rather than the Django
> defaults. This means you will need to learn how to override the Django
> default widgets, but that is an area that has much better
> documentation.
> 
> Yours,
> Russ Magee %-)
> 
> > 

-- 
urls = { 'fun':  'www.zonderbroodje.nl',  'tech':  'www.gp-net.nl' }


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Serving static file on Windows

2008-10-04 Thread mrsource

I can upload images on the right place in the file system, but then
django don't serve them.
I'm using the development server and the current SVN version of
django.

I have this configuration in settings.py:
MEDIA_ROOT = 'D:/codice/workspace/aurea/media/'
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/'


and in url.py:

from django.conf import settings
if settings.DEBUG
urlpatterns += patterns('django.views.static',
(r'^media/(?P.*)$',
'serve', {
'document_root':settings.MEDIA_ROOT,
'show_indexes': True }),)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Serving static file on Windows

2008-10-04 Thread Karen Tracey
On Sat, Oct 4, 2008 at 3:19 PM, mrsource <[EMAIL PROTECTED]> wrote:

>
> I can upload images on the right place in the file system, but then
> django don't serve them.
> I'm using the development server and the current SVN version of
> django.
>
> I have this configuration in settings.py:
> MEDIA_ROOT = 'D:/codice/workspace/aurea/media/'
> MEDIA_URL = '/media/'
> ADMIN_MEDIA_PREFIX = '/media/'
>

Do not use the same value for MEDIA_URL and ADMIN_MEDIA_PREFIX, as noted
here:

http://docs.djangoproject.com/en/dev/ref/settings/#admin-media-prefix

When you do this the admin media server built into the development server
handles everything under /media/, and the static server you have configured
in urls.py never sees the requests.

Karen


>
>
> and in url.py:
>
> from django.conf import settings
> if settings.DEBUG
>urlpatterns += patterns('django.views.static',
>(r'^media/(?P.*)$',
>'serve', {
>'document_root':settings.MEDIA_ROOT,
>'show_indexes': True }),)
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



GenericRelation

2008-10-04 Thread urukay


Hi,

could anyone help me with this please?
I'm working on rating system. Each model that can be rated has ARating as a
parent.
My models:

class ARating(models.Model):
"""Each model which is using ratings should extend this class.
"""
rates = generic.GenericRelation('Rating')

class Meta:
abstract = True


class Rating(models.Model):
user = models.ForeignKey(User) # rated by
value = models.PositiveSmallIntegerField(_('value')) # 1 to 5 (higher =
better)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')

__unicode__ = lambda self: unicode(self.user)

class Meta:
verbose_name = _('Rating')
verbose_name_plural = _('Ratings')

and the questions are:
how should I write view for model Rating, also form? I want to have one view
for every model that can be rated. How should I pass rated model to view
function?

Thanks a lot!

Radovan
-- 
View this message in context: 
http://www.nabble.com/GenericRelation-tp19816925p19816925.html
Sent from the django-users mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ManyToManyField edited on admin by both sides?

2008-10-04 Thread Markos Gogoulos

Solved, for reference check 
http://blog.abiss.gr/mgogoulos/entry/many_to_many_relationships_and



On Sep 19, 5:39 pm, Markos Gogoulos <[EMAIL PROTECTED]> wrote:
> Hi Jerry
>
> this doen't work with ManyToManyField
>
> Exception
>  has no ForeignKey to 
>
> Regards
>
> On Sep 19, 4:48 pm, Jerry Stratton <[EMAIL PROTECTED]> wrote:
>
> > On Sep 19, 6:45 am, Jerry Stratton <[EMAIL PROTECTED]> wrote:
>
> > > class SoftwareInline(admin.StackedInline):
> > >         model = Software
>
> > > class CategoryAdmin(admin.ModelAdmin):
> > >         inlines = [SoftwareInline]
>
> > Edit: shouldn't post before caffeine. The above might work, but I
> > don't know if it does; I used it yesterday with a ForeignKey, not a
> > ManyToManyField.
>
> > Jerry
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



installing tiny mce for flatpages

2008-10-04 Thread Bobby Roberts

hi group.  I need some help getting tinymce installed for flatpages in
admin.  I'm serving static content from an application called /static/
with tinymce located in /static/js/tiny_mce/.  I have read the docs on
creating an admin.py file and have done that as well but it's not
showing the richtext box... just the textarea.  Is there anyone out
there that can help?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Flatpages, get_absolute_url() and ABSOLUTE_URL_OVERRIDES

2008-10-04 Thread Erik Allik

from django.core.urlresolvers import reverse

def get_flatpage_absolute_url(o):
   return '%s%s' % (reverse('site-index'), o.url)

ABSOLUTE_URL_OVERRIDES = {
'flatpages.flatpage': get_flatpage_absolute_url
}

Actually I think this would work too:
ABSOLUTE_URL_OVERRIDES = {
'flatpages.flatpage': lambda o: '%s%s' % (reverse('site-index'), o.url)
}

Erik

On 04.10.2008, at 19:42, John Allen wrote:

>
> There are a few fairly recent threads touching this issue - including
> one of mine - but I'd like to ask a new question.
>
> The FlatPage model requires an explicity defined - ie hard-coded - URL
> and get_absolute_url() is set equal to this hard-coded URL (eg "/
> about/").
>
> For my purposes I needed to add a site-dependent root folder to all
> these URLs, which can be done like this in the settings.py file:
>
> ABSOLUTE_URL_OVERRIDES = {
>'flatpages.flatpage': lambda o: "/cms%s" % o.url,
> }
>
> so that the URL becomes /cms/about/
>
> This works fine but I am wondering: can the function in
> ABSOLUTE_URL_OVERRIDES make use of reverse(), so as to avoid hard-
> coding the "/cms" into the setting?
>
> I tried to do this with several variants of what looked to me (as a
> beginner) like plausible syntax, but none of them worked, and I could
> not find any examples on the web. Is there a way to do this, or is
> there some inherent limitation on the type of function which can be
> used with ABSOLUTE_URL_OVERRIDES?
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Recursive relationship - two models, same table

2008-10-04 Thread Steve Holden

Will Temperley wrote:
> Hi All
>
> I have a load of Institutions, some with departments, some not. So I
> created a model that can represent this simple hierarchy. See models
> at the bottom.
>
>  Fine, but a bit confusing for users, plus if the user just wants to
> deal with Institutions alone in the admin, they're faced with
> institutions and departments.  I'm relying heavily on the admin app in
> my project btw.
>
> So, I've tried having two models - InstitutionDepartment and
> Institution that have the same table but different managers- (see
> below). Institution doesn't use the "parent" foreign key.  (Btw I
> haven't used inheritance here cos copy and paste is quick and dirty.)
>
> I also have an Address model and JobPosition model that depend on
> "institution_department_id", therefore to make this work, I'll need
> two Address models with the same table?
>
> I've tried this and it works, it's just v messy! Is there a better way
> to do this??
> >From my point of view it would just be much easier to have multiple
> ModelAdmin classes use a single Model, but I can't do this can I?
>
>
> Cheers
>
> Will T
>
>
>
>
> class InstitutionDepartment(models.Model):
> TYPE_CHOICES = (
> ('I', 'Institution'),
> ('D', 'Department'),
> )
> institution_department_id = models.AutoField(primary_key=True)
> name = models.CharField(max_length=200)
> acronym = models.CharField(max_length=10,  null=True, blank=True)
> type = models.CharField(max_length=1,  choices=TYPE_CHOICES)
> parent = models.ForeignKey('self',  null=True,  blank=True)
> def __unicode__(self):
> if self.parent:
> return ' | '.join([self.parent.name,  self.name, ])
> else:
> return self.name
> class Meta:
> db_table = 'institution_department'
> ordering = ['parent__name', 'name', ]
>
> class Institution(models.Model):
> TYPE_CHOICES = (
> ('I', 'Institution'),
> ('D', 'Department'),
> )
> institution_department_id = models.AutoField(primary_key=True)
> name = models.CharField(max_length=200)
> acronym = models.CharField(max_length=10,  null=True, blank=True)
> objects = InstitutionManager()
> type = models.CharField(max_length=1,  choices=TYPE_CHOICES)
> def __unicode__(self):
> return self.name
> class Meta:
> db_table = 'institution_department'
>
>
> class StreetAddress1(StreetAddressAbstract):
> institution_department =
> models.OneToOneField(InstitutionDepartment)
> class Meta(StreetAddressAbstract.Meta):
> pass
>
> class StreetAddress2(StreetAddressAbstract):
> institution_department = models.OneToOneField(Institution)
> class Meta(StreetAddressAbstract.Meta):
> pass
I could be wrong (it's happened before :-) but it seems to me that many
time the contortions people go through to make the admin interface do
what they want actually end up taking more time than writing the
necessary customized views.

Sorry if this isn't helpful, but I have seen many cases where people ask
"how do I make the admin interface do (something it was never intended
to)". Django allows you to build custom views with custom templates so
easily it seems a shame to have to mangle the admin system to manage
contorted models just to avoid writing a little custom code.

regards
 Steve

regards
 Steve



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Serving static file on Windows

2008-10-04 Thread mrsource

You're right...the ADMIN_MEDIA_PREFIX is routed before MEDIA_URL.
Changing one of them has solved my issue.
Carlo


On 4 Ott, 21:34, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Sat, Oct 4, 2008 at 3:19 PM, mrsource <[EMAIL PROTECTED]> wrote:
>
> > I can upload images on the right place in the file system, but then
> > django don't serve them.
> > I'm using the development server and the current SVN version of
> > django.
>
> > I have this configuration in settings.py:
> > MEDIA_ROOT = 'D:/codice/workspace/aurea/media/'
> > MEDIA_URL = '/media/'
> > ADMIN_MEDIA_PREFIX = '/media/'
>
> Do not use the same value for MEDIA_URL and ADMIN_MEDIA_PREFIX, as noted
> here:
>
> http://docs.djangoproject.com/en/dev/ref/settings/#admin-media-prefix
>
> When you do this the admin media server built into the development server
> handles everything under /media/, and the static server you have configured
> in urls.py never sees the requests.
>
> Karen
>
>
>
> > and in url.py:
>
> > from django.conf import settings
> > if settings.DEBUG
> >    urlpatterns += patterns('django.views.static',
> >    (r'^media/(?P.*)$',
> >        'serve', {
> >        'document_root':settings.MEDIA_ROOT,
> >        'show_indexes': True }),)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Resizing images when uploading

2008-10-04 Thread varikin



On Oct 3, 4:18 pm, "Juanjo Conti" <[EMAIL PROTECTED]> wrote:
> Hi, I used to use a pre 1.0 svn version of Django. There I had this class:
>
> class Foto(models.Model):
>     descripcion = models.CharField(max_length=30, blank=True,
> verbose_name=u"descripción")
>     imagen = models.ImageField(upload_to='imagenes', verbose_name=u"foto")
>     inmueble = models.ForeignKey(Inmueble)
>
>     
>
>     def _save_FIELD_file(self, field, filename, raw_contents, save=True):
>         '''
>         Se reescribe el metodo de la clase padre para definir el
> nombre de archivo con
>         el que se guardará la imagen en el sistema de archivos. Se
> utilizan enteros crecientes.
>         '''
>         if TESTING:
>             field.upload_to = 'tests_dest'
>         filename = Foto._cambio_de_nombre(filename)
>         raw_contents = Foto._ajustar_tamanio(raw_contents)
>         super(Foto, self)._save_FIELD_file(field, filename, raw_contents, 
> save)
>
> The  _save_FIELD_file method was redefined to change the file name and
> resize it. Now in 1.0 I can rename the filename with a callable to use
> as upload_to ImageField argument:
>
> def _upload_to(instance, filename):
>     intancia.imagen. raw_contents = Foto._ajustar_tamanio(raw_contents)
>     filename = Foto._cambio_de_nombre(filename)
>     if TESTING:
>         return os.path.join('tests_dest', filename)
>     return os.path.join('imagenes', filename)
>
> but I don't know where I have to put my code to resize the image
> before it gets saved. Can anyone help me?
>
> Thanks,
>
> Juanjo

I have been overriding the save method on the model.  I have found
that by the time the save method is called, the file is saved to the
disk already, So I open the original, resize and save to the
thumbnail:

class Picture(models.Model)
name = models.CharField(max_length=200)
original = models.ImageField(upload_to='original')
thumbnail = models.ImageField(upload_to='thumbnail')

def save(self, **kwargs):
orig = Image.open(self.original.path)
name = os.path.basename(self.original.name)
height = int(100 * orig.size[1] / orig.size[0])

thumb = orig.resize((width, height), Image.ANTIALIAS)
thumb_file = tempfile.NamedTemporaryFile('w+b')
resized.save(thumb_file, 'JPEG')
self.thumbnail.save(name, File(thumb_file), False)
thumb_file.close()

   super(Picture, self).save(**kwargs)

I have to save the resized image to a temp file because
self.thumbnail.save takes a django.core.files.File object which takes
an python file object in the constructor.  I would love to be able to
use an in memory object instead of a temp file, but that isn't in
possible yet.

John
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: add() method on ManyToManyField

2008-10-04 Thread Steve Holden

You could also think about actioning a pre- or post-save signal if that
would allow you to access the pieces you need.

regards
 Steve

AndyH wrote:
> OK... thinking about this, I guess add() on a ManyToManyField is just
> a wrapper around the save() method of the model your saving it on to.
> I can do what I need inside save() and that works fine. Probably more
> transparent as well.
>
> Ta.
> Andy.
>
>
> On Oct 1, 9:13 pm, AndyH <[EMAIL PROTECTED]> wrote:
>   
>> Hello,
>>
>> Is it possible to override the add() method that appears to be on a
>> ManyToManyField attribute. For example:
>>
>> cheese = Topping(name="cheese")
>> cheese.save()
>> pizza.toppings.add( cheese )
>>
>> I want to override this add method to add extra code before calling
>> the original add().
>>
>> I tired to do this by subclassing models.ManyToManyField, but I
>> doesn't appear that that class actually has an add() method.
>>
>> Any thoughts on the best way to achieve this?
>>
>> Regards and thanks.
>> Andy.
>> 
> >
>
>   



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: mptt + contrib.comments?

2008-10-04 Thread pihentagy

Hi!

What about thins project?

http://code.google.com/p/django-threadedcomments/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Need help with djangosearch app

2008-10-04 Thread M Godshall

First of all, I'm trying to find a simple search solution that will
allow me to search specific fields in a model and display the results
according to their relevance (I'm using mysql).  After much searching
it seemed like the djangosearch app would be the best solution (but I
welcome other suggestions!)

However, I'm having trouble implementing the djangosearch app found at
http://code.google.com/p/djangosearch/source/browse/branches/soc-new-backends/?r=18#soc-new-backends/djangosearch.
The instructions that I'm following are found at
http://code.google.com/p/djangosearch/source/browse/branches/soc-new-backends/doc/README.txt?r=18.
Basically, I've setup that app as instructed, and I'm running searches
without any errors.  However, I'm not getting any results, even for
searches that I know should return something.  I wasn't able to get
any help from the irc, so I would appreciate if someone could take a
look at my code and point me in the right direction: http://dpaste.com/82410/.

Any help would be appreciated!  Thanks in advance!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Need help with djangosearch app

2008-10-04 Thread M Godshall

After a little work, I realized that it IS performing the search,  but
it only returns objects with fields that match EXACTLY.  Is there any
way to make it so it does a partial search as well?  Like if a field
contains part of that query, it still finds it?

On Oct 4, 7:07 pm, M Godshall <[EMAIL PROTECTED]> wrote:
> First of all, I'm trying to find a simple search solution that will
> allow me to search specific fields in a model and display the results
> according to their relevance (I'm using mysql).  After much searching
> it seemed like the djangosearch app would be the best solution (but I
> welcome other suggestions!)
>
> However, I'm having trouble implementing the djangosearch app found 
> athttp://code.google.com/p/djangosearch/source/browse/branches/soc-new-
> The instructions that I'm following are found 
> athttp://code.google.com/p/djangosearch/source/browse/branches/soc-new-
> Basically, I've setup that app as instructed, and I'm running searches
> without any errors.  However, I'm not getting any results, even for
> searches that I know should return something.  I wasn't able to get
> any help from the irc, so I would appreciate if someone could take a
> look at my code and point me in the right direction:http://dpaste.com/82410/.
>
> Any help would be appreciated!  Thanks in advance!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django log for admin

2008-10-04 Thread sanrioyt

Thanks Rajesh.

This will work. Unfortunately, the last_login field gets overwritten
every time
the user logs in, but at least, it gives me a starting point.

Thanks,
sanrio

On Oct 2, 3:41 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> > I have an application based around the admin. Is there a way to find
> > out which users have logged on to the application?
>
> You could look at the last_login field in the User objects.
>
> -RD
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Flatpages, get_absolute_url() and ABSOLUTE_URL_OVERRIDES

2008-10-04 Thread Malcolm Tredinnick


On Sat, 2008-10-04 at 09:42 -0700, John Allen wrote:
[...]
> This works fine but I am wondering: can the function in
> ABSOLUTE_URL_OVERRIDES make use of reverse(), so as to avoid hard-
> coding the "/cms" into the setting?

No, you can't do this. The rule is that you cannot use any pieces of
Django itself in your settings file (and ABSOLUTE_URL_OVERRIDES is a
setting). This is because Django relies on using your settings, so
there's almost always a chicken-and-egg sort of problem.

In this case, reverse() depends on knowing about your URL configuration.
But that is specified by the ROOT_URLCONF setting (and possibly some
other settings), so reverse() requires the settings to be fully loaded,
leading to an obvious catch-22.

Regards,
Malcolm




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---