retrieving models without importing

2009-09-09 Thread nbv4

I remember reading about away to use django models without importing,
but google fails me. I want to create a ForeignKey relation to another
model, but I can't import it because that will call an endless loop of
imports.

I know about doing:

field = models.ForeignKey("app.Model")

but theres a bug in django (at least there was last time I ran into
it) that causes a showstopper error in mod_wsgi. So thats out of the
question.

I remember it being something like:

from django.utils import get_model
Model = get_model("app", "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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



User profile creation forms

2009-09-09 Thread Rodney Topor

Suppose one wants to store additional information about a user in a
separate profile class as described in the documentation.  When a user
registers, the form displayed should show (all) fields from class User
and (some) fields from class Profile.

What is the best way to define this form?

What is the best way to process the form data in a view to create the
user instance and associated profile instance?

I'm sorry if this is a naive question.  Neither the documentation nor
The Django Book appear to answer it.  It seems to me to be a common
situation.

Rodney
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Long user creation forms

2009-09-09 Thread Rodney Topor

The default UserCreationForm in django.contrib.auth.forms only asks
for username and password.  Given that users also have first and last
names and emails, it would be natural for the default form to provide
fields for these also.  One way to provide these extra fields is to
define a subclass of UserCreationForm in forms.py as follows:

from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

class LongUserCreationForm(UserCreationForm):

class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email']

And then replace occurrences of UserCreationForm() in views by
LongUserCreationForm().

But, and this is my question, is this the right way to do this or is
there a better way?

Rodney
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



remember me

2009-09-09 Thread putih

i'm facing a problem for remember_me function but it's actually not
working. below are my code:-

_views.py

_from django.contrib.auth import REDIRECT_FIELD_NAME
from django.views.decorators.cache import never_cache


def remember_me_login (
   request,
   template_name = 'registration/login.html',
   redirect_field_name = REDIRECT_FIELD_NAME,
   ):

   """
   Based on code cribbed from django/trunk/django/contrib/auth/
views.py
 Displays the login form with a remember me checkbox and handles
the login
   action.
 """
   from django.conf import settings
   from django.contrib.sites.models import RequestSite, Site
   from django.http import HttpResponseRedirect
   from django.shortcuts import render_to_response
   from django.template import RequestContext
 from remember_me.forms import AuthenticationRememberMeForm
 redirect_to = request.REQUEST.get ( redirect_field_name, '' )
 if request.method == "POST":
 form = AuthenticationRememberMeForm ( data = request.POST, )
 if form.is_valid ( ):
 # Light security check -- make sure redirect_to isn't
garbage.
 if not redirect_to or '//' in redirect_to or ' '
in redirect_to:
 redirect_to = settings.LOGIN_REDIRECT_URL
 if not form.cleaned_data [ 'remember_me' ]:
 request.session.set_expiry ( 0 )
 from django.contrib.auth import login
 login ( request, form.get_user ( ) )
 if request.session.test_cookie_worked ( ):
 request.session.delete_test_cookie ( )
 return HttpResponseRedirect ( redirect_to )
 else:
 form = AuthenticationRememberMeForm ( request, )
 request.session.set_test_cookie ( )
 if Site._meta.installed:
 current_site = Site.objects.get_current ( )
 else:
 current_site = RequestSite ( request )
 return render_to_response (
   template_name,
   {
   'form': form,
   redirect_field_name: redirect_to,
   'site': current_site,
   'site_name': current_site.name,
   },
   context_instance = RequestContext ( request ),
   )
remember_me_login = never_cache ( remember_me_login )

_forms.py_

class AuthenticationRememberMeForm ( AuthenticationForm ):

   """
   Subclass of Django ``AuthenticationForm`` which adds a remember me
checkbox.
 """
 remember_me = forms.BooleanField (
   label = _( 'Remember Me' ),
   initial = False,
   required = False,
   )

please advise me on this matter.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Model manger for the abstract model.

2009-09-09 Thread Alexandre Djioev
Hi everyone,

I have an abstract model EventComponent, and from this model I inherit two
models - EventCollection (non-abstract) and Event (abstract). I also inherit
from Event model and create non-abstract models, for example ClassEvent,
LectureEvent e.c.
I want to:

EventComponent.objects.all()

that will return me all EventCollection objects and all ClassEvent,
LectureEvent e.c. objects (so all those that are not abstract).
First of all is it correct to say that abstract models don't have managers,
and you have to add them manually? When I poke my EventComponent i can see
that objects object is not defined.
Second -  how do I write a manager that will do this job for me? Or at least
a direction where to dig would be good...


Cheers, Alex

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



Leaking python app structure

2009-09-09 Thread Eric Abrahamsen

I have a site with SEND_BROKEN_LINK_EMAILS = True in the settings,  
which means I get both legitimate 404s and also probes where the bot  
is being clever by putting the fake URL in the referer heading.

Today I got a series of 404 messages that were alarming because they  
were probing legitimate urls with parts of my application structure  
appended to the end. Something like 
http://mysite.com/actual/url/appname.modelname 
, with the name of an app and a model stuck on the end with a dot in  
between, just like you'd see in a python import statement.

I can't think of any place in the public-facing site where the names  
of any models appear directly, let alone the name of an app. This  
makes me nervous. Has anyone seen anything like this before? I can't  
think of any immediate threat it could pose, but nevertheless this  
seems like a Bad Thing. Any words of wisdom?

Thanks,
Eric

--~--~-~--~~~---~--~~
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: PostgreSQL or MySQL, What are the +'s and -'s?

2009-09-09 Thread Jason Beaudoin
>
>
>  @Jason - I think that's the number one reason I'm going to PostgreSQL. I
> don't use everything all the time but I really like to have the widest array
> of query syntax options. MySQL is just too limiting, especially when
> PostgreSQL is available.
>
>
The other issue I have with MySQL is the "flexibility" to choose your own
db/table engine (sorry if that isn't the correct terminology). While some
find this a plus, and indeed, in *some* cases you want this sort of
flexibility as some of the more obscure database environments would benefit
from peculiarities of one engine over another, I don't find this sort of
thing as attractive.

The reasoning is that of simplicity - as an engineer and artist, I put a lot
of value in simplicity of design, implementation, and maintenance. While I
don't have a lot of experience with MySQL, the more I've read about it's
design and this engine "flexibility" the more I've been turned away. In my
mind, it is as analogous to the linux to BSD situation.. on one hand you
have a lot of flexibility (package managers, configuration tools, etc).. but
in reality it turns into a total rat's nest in comparison to the
"smoothness" of BSD.

just my 2 cents..

~Jason

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



Permissions per model instance

2009-09-09 Thread eka

Hi all..

Is there any way to assign permissions to an instance of a model
instead of to a model itself?

Example:

I have a model for Files so john can (view) file 1, 5 and 6 but not
the rest

Regards

Eka
--~--~-~--~~~---~--~~
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: Incorrect {{root_path}} in classes derived from AdminSite

2009-09-09 Thread Ramiro Morales

On Wed, Sep 9, 2009 at 1:16 PM, Vlastimil Zima  wrote:
>
> Neither name nor app_label fixed situation.
> AdminSite instance django.contrib.admin.site is constructed without
> any names and it works.
> In documentation is written: "If no instance name is provided, a
> default instance name of admin will be used."

Ah, then you either need to either override only the get_urls() method
and leave the urls() method/url property one to be handled Django or to
write your urls() method so it returns the three tuple the rest of the
admin code is expecting (you are retuning a a single value).

This new capability was added in Django 1.1 core as part of
the URL namespacing changes and and is described both here:

http://docs.djangoproject.com/en/dev/topics/http/urls/#defining-url-namespaces

and in the Django 1.1 release notes.

HTH,

-- 
Ramiro Morales
http://rmorales.net

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



What is the correct database format for storing a 2-dimensional table?

2009-09-09 Thread W.P. McNeill

I am writing a Django app to store and manipulate a 2-dimensional
table of data.  I don't think I'm trying to do anything particularly
difficult, but I'm new to both Django and relational databases, so I'm
getting confused by various design considerations.  I'm hoping there
are canonical answers to the questions I ask below that will be
obvious to people in this group.

The rows of the table are called "phonemes" and the columns are called
"features".  For a given phoneme, the features all take on the values
+, -, or undefined.  A feature value is specified only once for every
phoneme.  To make things more concrete, here is a Google spreadsheet
representation of what I want:

http://spreadsheets.google.com/pub?key=t1WKdNNiy_JZgFLVui0XETA&output=html

The funny-looking symbols are the names of the phonemes, and the all-
caps words like SYLLABIC, STRESS, LONG etc. are features.  (Sorry to
bombard everyone with terminology from linguistics.  I thought about
translating to a more familiar problem domain, but decided I would
just get myself more confused in the process.)

This is not apparent from the spreadsheet linked above, but to each of
the phonemes and features I need to attach URIs that point to metadata
stored elsewhere on the web.

A few questions:

1. What is the correct database table design for this problem?
2. How much well-formedness validation (e.g. restricting values to
+,-,undefined, ensuring there is only one feature per phoneme) can I
get automatically from the database table design and how much do I
have to write as code?
3. What is the best way to get a spreadsheet-like user interface,
where a user clicks on a cell in a table and is presented with a "+/-/
undefined" selection box?

For question (1), I think I definitely want Phoneme and Feature
tables, each of which have Name and URI fields.  However, I'm
uncertain what the relationship between these tables should be.  I've
tried various one-to-many, many-to-many, many-to-many-through-another-
table configurations, and they all have their problems.

I suspect the answer to (2) is that I can get all the validation out
of the table design.

For (3), I've only played with the admin interface so far.  I don't
know if its most Djangonic to use this or write my own views.

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



Django-logging in production mode

2009-09-09 Thread eli

Hi,

It's a good idea to logging errors, notices etc using python module
logging in app under production mode (Nginx)?

I know about for ex: sending error:500 emails to admins etc, but
sometimes I want to log errors and lets app go on.

(I'm talking about logging errors to the file, and later sending it
via email using cron)

regards.
--~--~-~--~~~---~--~~
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: Is it secure "enough" to put login info in the session?

2009-09-09 Thread ristretto.rb

Hi Craig,

I'm considering something like this

Trigger:  User comes to site for the first time
1.  User requests to be a guest
2.  system creates a guest User with randomness for username and
password, authenticates and logs in the user, also sets a cookie in
the browser with the id of the Guest User.
3.  User has full access to the site, however some features will be
limited.


Trigger:  User returns to site
1.  User requests to be a guest, and expects to see the data created
in the first session
2.  System checks cookie in browser for an ID, if one is found, find a
matching Guest User, auth and login
3.  User continues to us the site

If the user tried to log in as a guest from another computer, they
will, of course, not see they're information.  In fact, they will see
the information that was saved, if a guest was every created on that
machine.  I'm not too worried about that at this point.

I'm just working through when Django saves a cookie, and I think this
will work.

Gene





On Sep 9, 5:54 pm, Craig McClanahan  wrote:
> On Tue, Sep 8, 2009 at 10:20 PM, ristretto.rb wrote:
>
> > Hi
>
> > I want to have a guest concept.  You get instant access to my app.
> > There are limits.  But, you will be allowed to come back multiple
> > times before I require you to register.
>
> How do you plan to tell if the guest "came back"?  The only reasonable
> mechanism I can think of is to use a session cookie (you can't rely on
> things like IP address ... like most folks with a home router, all the
> computers in my household will appear to have the same IP address to a
> service we contact, and the same would be true for most business
> situations).  And even if you rely on a session cookie, your
> restrictions are easily bypassed by the user who simply clears their
> cookie cache.
>
> Until you can solve this problem reliably (good luck!), the
> implementation details are not really worth thinking about.  But
> things like using a session cookie are no more or less secure for this
> use case than they are for the usual approach to keep a user logged on
> to a web app, other than the fact that you'd probably need to keep
> your session alive a lot longer.
>
> Craig
>
> PS:  The typical solution I've seen for a "guest" concept is to offer
> only a limited subset of the overall functionality to non-registered
> users, with lots of teasers about "if you would only bother to
> register, you could do FOO and BAR and BAZ!".  Example:  ESPN's web
> site has a bunch of "freely available" stories accessible to anonymous
> users, but the (presumbably) good stuff requires a login.  Figuring
> out the balance point is a challenge -- for me, for example, I'm not a
> fantasy football junkie, so the extra subscribers-only analysis
> doesn't have enough value for me to bother to register (or pay, as the
> case may be).
>
>
>
> > When a user comes in as a guest, I will create a user with a bogus
> > username, password and email, and put  the user_id in the session, so
> > that when the user comes back I can read it and restore saved state.
>
> > I'm mildly concerned that it's unsafe to put the user_id in the
> > session.  I can imagine a hacker faking that somehow, and getting
> > access to other guest accounts.  I'm not sure the risk is that big,
> > and once users register, the risk goes down.  But, I'm wondering if
> > this is at all foolhardy.  Is there a better way to approach this?
>
> > Perhaps a hash key or something that isn't sequentially too
> > guessable.  Or some encryption.
>
> > This guest concept has inherent security issues with shared computers:
> > labs, cafes, etc.  The user will made aware of this when logging in as
> > Guest.  Also there will be no sensitive or private data in this guest
> > account that if seen by another user would make much difference.
>
> > Thanks for any insight
> > Gene
--~--~-~--~~~---~--~~
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: Custom url in django Django sitemap

2009-09-09 Thread eli

Hi,

Thanks for replay, but I was talking about the django sitemap
framework http://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/ ,
and problem: how to add my custom page (serving by server) to output
(XML) of the django sitemap framework?

regards.

On 9 Wrz, 18:47, Peter Coles  wrote:
> Hi eli,
>
> If you want serve a "static file" (that never changes and doesn't take
> advantage of django's template system) then you shouldn't be serving
> it with django.  You can use django if you really 
> want:http://docs.djangoproject.com/en/dev/howto/static-files/but you're
> better off having your server (like apache) handle it 
> directly:http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id1
>
> However, you may want your about-me page to inherit a header and
> footer or other stuff from a base template (if you don't know what I'm
> talking about read 
> this:http://docs.djangoproject.com/en/dev/intro/overview/#intro-overview
> ) -- if that's the case, you can use the direct_to_template generic
> view as described here:
>
> http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-...
>
> -Peter
>
> On Sep 9, 11:41 am, eli  wrote:
>
> > Hi,
>
> > How to add custom static url (they are not in database) to Django
> > Sitemap? for ex: /about-me.html, /contact.html, /some-static-url.html
>
> > regards.
--~--~-~--~~~---~--~~
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: Having Trouble with Reverse method

2009-09-09 Thread Streamweaver

Yet more info here.  This might be a particular problem due to the
particular method being called in multiple URL patterns so I tried
making it and calling a named URL pattern but am getting the same
message.


On Sep 9, 5:18 pm, Streamweaver  wrote:
> Thanks for all the replies.  I'm on Django 1.0.2 btw if it makes a
> difference, I see the extra-patterns.  I'm also running this via the
> manage.py runserver on a development machine and not in staging or
> production.
>
> For the original authors, those variations turn up the same error.
>
> To Peters enumerated questions.
>
> 1.  yep it resolves fine.
> 2.  It seems to be.  It's replicated in both settings.py and
> localsettings.py.
> 3.  the ROOT_URLCONF points to my base app urls.py and that points to
> the subsequent urls.py under that project via the line
> (r'^project/', include('dwrangler.project.urls')).  Both of these
> contain a urlpatterns attribute.
>
> So the method I'm calling isn't in dwrangler.urls but in
> dwrangler.project.urls
>
> Additional curiousities, if I kill the lighthttp server and restart it
> I get a new error:
>
>         "Caught an exception while rendering: Reverse for 'dwrangler.project-
> root' with arguments '()' and keyword arguments '{}' not found."
>
> This is interesting because it's throwing the error message for a
> template tag that has worked that calls a names URL pattern in the
> dwrangler.project.urls file.  So this seems to be only reading from
> the dwrangler.urls file and not the included dwrangler.project.urls
>
> I'm still struggling with this so any other insight may help.
>
> Thanks for all the feedback so far.
>
> On Sep 8, 5:31 pm, Peter Coles  wrote:
>
> > What you provided looks correct -- which means that something else is
> > probably broken...
>
> > Some things to investigate:
>
> > 1. If you manually go that url: http:/in_development/
> > does anything get served?
> > 2. Is your ROOT_URLCONF setup to properly point to this file in your
> > settings file?
> > 3. Is this another url file than the one defined in your ROOT_URLCONF?
> > If so are you properly "including" this one from your root urls.py?
> > Details on include 
> > here:http://docs.djangoproject.com/en/dev/topics/http/urls/#including-othe...
>
> > You'll find a wealth of information about urls in django 
> > here:http://docs.djangoproject.com/en/dev/topics/http/urls/
>
> > Once you get it working, you may find it more convenient to use named
> > url 
> > patterns:http://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-pat...
>
> > On Sep 8, 1:49 pm, Streamweaver  wrote:
>
> > > I'm having trouble understanding the output of the reverse method.
>
> > > I have the following URL pattern:
>
> > > urlpatterns = patterns('dwrangler.project.views',
> > >     (r'^in_development/$', 'summary_in_development'),
> > > )
>
> > > from the documentation I would think I can get the URL by using
>
> > > reverse('dwrangler.project.views.summary_in_development')
>
> > > But I keep getting a NoReverseMatch error.  I have tried several
> > > different formats but keep getting similar errors.
>
> > > I must be missing something obvious and would be thankful if something
> > > could point me in the right direction.
>
> > > Thanks
--~--~-~--~~~---~--~~
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: Having Trouble with Reverse method

2009-09-09 Thread Streamweaver

Thanks for all the replies.  I'm on Django 1.0.2 btw if it makes a
difference, I see the extra-patterns.  I'm also running this via the
manage.py runserver on a development machine and not in staging or
production.

For the original authors, those variations turn up the same error.

To Peters enumerated questions.

1.  yep it resolves fine.
2.  It seems to be.  It's replicated in both settings.py and
localsettings.py.
3.  the ROOT_URLCONF points to my base app urls.py and that points to
the subsequent urls.py under that project via the line
(r'^project/', include('dwrangler.project.urls')).  Both of these
contain a urlpatterns attribute.

So the method I'm calling isn't in dwrangler.urls but in
dwrangler.project.urls

Additional curiousities, if I kill the lighthttp server and restart it
I get a new error:

"Caught an exception while rendering: Reverse for 'dwrangler.project-
root' with arguments '()' and keyword arguments '{}' not found."

This is interesting because it's throwing the error message for a
template tag that has worked that calls a names URL pattern in the
dwrangler.project.urls file.  So this seems to be only reading from
the dwrangler.urls file and not the included dwrangler.project.urls

I'm still struggling with this so any other insight may help.

Thanks for all the feedback so far.





On Sep 8, 5:31 pm, Peter Coles  wrote:
> What you provided looks correct -- which means that something else is
> probably broken...
>
> Some things to investigate:
>
> 1. If you manually go that url: http:/in_development/
> does anything get served?
> 2. Is your ROOT_URLCONF setup to properly point to this file in your
> settings file?
> 3. Is this another url file than the one defined in your ROOT_URLCONF?
> If so are you properly "including" this one from your root urls.py?
> Details on include 
> here:http://docs.djangoproject.com/en/dev/topics/http/urls/#including-othe...
>
> You'll find a wealth of information about urls in django 
> here:http://docs.djangoproject.com/en/dev/topics/http/urls/
>
> Once you get it working, you may find it more convenient to use named
> url 
> patterns:http://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-pat...
>
> On Sep 8, 1:49 pm, Streamweaver  wrote:
>
> > I'm having trouble understanding the output of the reverse method.
>
> > I have the following URL pattern:
>
> > urlpatterns = patterns('dwrangler.project.views',
> >     (r'^in_development/$', 'summary_in_development'),
> > )
>
> > from the documentation I would think I can get the URL by using
>
> > reverse('dwrangler.project.views.summary_in_development')
>
> > But I keep getting a NoReverseMatch error.  I have tried several
> > different formats but keep getting similar errors.
>
> > I must be missing something obvious and would be thankful if something
> > could point me in the right direction.
>
> > Thanks
--~--~-~--~~~---~--~~
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 invoke hasNoProfanities?

2009-09-09 Thread Chris Withers

Brandon Taylor wrote:
> I would like to do some obscenity filtering on posts, and I see there
> is a setting: PROFANITIES_LIST
> 
> But, how to I invoke the hasNoProfanities validator? I searched the
> django source code for this, but the only thing I could find was the
> setting in conf > global_settings.py
> 
> I'd appreciate some pointers.

It's in the book, which is free to read online at http://djangobook.com/

cheers,

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

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



How to invoke hasNoProfanities?

2009-09-09 Thread Brandon Taylor

Hi everyone,

I would like to do some obscenity filtering on posts, and I see there
is a setting: PROFANITIES_LIST

But, how to I invoke the hasNoProfanities validator? I searched the
django source code for this, but the only thing I could find was the
setting in conf > global_settings.py

I'd appreciate some pointers.

Thanks,
Brandon
--~--~-~--~~~---~--~~
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 generate po files ?

2009-09-09 Thread Mirat Can Bayrak

i am calling like python manage.py compilemessages < so django settings module 
set before compilemessages command executed :/ (i think)

--~--~-~--~~~---~--~~
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: Choices of foreign keys?

2009-09-09 Thread Peter Coles

Oh sorry, thought you wanted multiple categories per photo. Tim's
response above is good.

As he said, I'd go with the ForeignKey approach, this makes the
categories easier to manage and gives you further flexibility of
storing additional information within each category (if you want).
Also his examples of choices are good, it will be a bit of a pain if
you use choices and choose to rename or remove any of them.

On Sep 9, 1:36 pm, Léon Dignòn  wrote:
> Hello Peter,
>
> sorry, I was talking about choices, not a choice 
> field:http://docs.djangoproject.com/en/dev/ref/models/fields/#choices
>
> Since any photo can only belong to one category (because I say so :) I
> would tend towards using 1:N instead of M:N. Or did I missunderstand
> you? If one photo can belong to several cetegories, I would use your
> ManyToManyField, is that right?
>
> You say that an object should be represented as a table in SQL. I know
> that, too. But the choices I mentioned above, are confusing me. Can
> you explain me why they exist, or give me a good example that justify
> choices?
>
> -leond
>
> On Sep 9, 6:36 pm, Peter Coles  wrote:
>
> > Hey Léon,
>
> > ChoiceField is a form field, not a table column—maybe you're thinking
> > about CommaSeparatedIntegerField? You could use that and hardcode
> > which categories represent which ids in your python 
> > code.http://docs.djangoproject.com/en/dev/ref/models/fields/#commaseparate...
>
> > On the other hand, the standard way of representing an object and its
> > categories in SQL is to use a ManyToMany relation. This approach
> > easily handles everything you want to do in a much easier to manage
> > format, and it's unlikely that you'll need to worry about "bloat"—
> > optimizing how you serve web pages, static files, caching, etc. will
> > give you *many* more gains than holding off from adding another table
> > to your db.
>
> > To setup your category, you can add something like this to your models
> > file (above your photos model):
>
> > class Category(models.Model):
> >     title = models.CharField(max_length=100)
> >     slug = models.SlugField(unique=True)
> >     class Admin:
> >         pass
>
> > and then inside your photos model add a new column:
>
> >     categories = models.ManyToManyField(Category, blank=True)
>
> > -Peter
>
> > On Sep 9, 11:54 am, Léon Dignòn  wrote:
>
> > > Hello,
>
> > > let's assume we have a model for photos with the fields id, user,
> > > photo. Any user should be able to categorize his foto with a given
> > > number of categories, e.g. person, car, building. In future it's
> > > possible that I add more categories.
>
> > > My question is whether the new category field should be a ChoiceField,
> > > or a ForeignKey?
>
> > > I would prefer a ChoiceField because
> > > - I am 99% sure that there won't be new categories.
> > > - the only person who maybe adds a new category will be me.
> > > - another model would bloat up my database and my models.py
>
> > > But maybe I should use a ForeignKey because,
> > > - I don't have to edit the model/table.
> > > - it's easier to add a choice to a table than in the source code.
> > > - because values in databases should be atomic.
>
> > > Otherwise, assuming that syncdb can't handle adding new choices to an
> > > existing table, adding a choice directly in the database application
> > > (MySQL, PostgreSQL) is no problem. Removing a choice won't happen.- Hide 
> > > quoted text -
>
> > - Show quoted text -
--~--~-~--~~~---~--~~
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: Choices of foreign keys?

2009-09-09 Thread Tim

For something like categories, I would go with a separate model and
use ForeignKey. For that 1% chance when you have to add a new
category, it will be a lot easier. Plus, what if requirements change
in the future and you are adding/deleting categories more than you
anticipated?

Using choices with a char/integer field is good for lists of options
that will *never* change... gender (M,F), age ranges (0-18,19-25,etc),
statuses (published,draft).
--~--~-~--~~~---~--~~
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: foreign key not generated when pointing to a model in another application

2009-09-09 Thread jim

True, but the FOREIGN KEY constraints generated are merely ignore by
sqlite.

However, the CREATE statement should be correct because when I port
this to say MySQL, it will be a problem.

For any other example the FOREIGN KEY constrains are generated
corrcetly in sqlite (athough they are ignore by the sqlite engine.
)

On Sep 9, 9:33 am, Daniel Roseman  wrote:
> On Sep 9, 5:29 pm, jim  wrote:
>
>
>
> > Am using sqlite3 and django version 1.0
>
> > class U(models.Model):
> >     woid = models.ForeignKey('workorder.X')
>
> > In the workorder app I have:
>
> > class X(models.Model):
> >     woid = models.CharField(max_length=20, primary_key=True)
>
> > When I try :
>
> > python manage.py sql ceuser
>
> > I get
>
> > CREATE TABLE "ceuser_u" (
> >     "id" integer NOT NULL PRIMARY KEY,
> >     "woid_id" varchar(20) NOT NULL
> > )
> > ;
>
> > As can be seen, the class ceuser does not have the FOREIGN KEY
> > constraint...
>
> > seen some threads abut it but no solution...
>
> Sqlite does not support foreign key constraints. 
> Seehttp://www.sqlite.org/omitted.html
> --
> DR
--~--~-~--~~~---~--~~
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 generate po files ?

2009-09-09 Thread Mike Ramirez
On Wednesday 09 September 2009 10:55:54 Mike Ramirez wrote:

> # export DJANGO_SETTINGS_MODULE=myproject.settings
> # django_admin.py makemessages
>
> For windows I believe it's:
>
> C:\> set DJANGO_SETTINGS_MODULE=myproject.settings
> C:\> django_admin.py makemessages
>

I forgot to add that myproject should live within your PYTHONPATH setting or 
run the command in the parent directory of myproject

Info on DJANGO_SETTINGS_MODULE with django-admin.py

http://docs.djangoproject.com/en/dev/topics/settings/#the-django-admin-py-
utility

for more info on PYTHONPATH

http://docs.python.org/tutorial/modules.html#the-module-search-path

Mike
-- 
You cannot see the wood for the trees.
-- John Heywood


signature.asc
Description: This is a digitally signed message part.


Re: How to generate po files ?

2009-09-09 Thread Mike Ramirez
On Wednesday 09 September 2009 10:40:47 Léon Dignòn wrote:
> I am glad you ask this. I was running in that problem too.
> I use Windows Vista and I've run 'django-admin.py makemessages' inside
> the folder I also run 'django-admin.py startproject bestsiteever'.
> Same error.
>
> -leond
>
> On Sep 9, 7:28 pm, Mirat Can Bayrak  wrote:
> > Hi, i finished my site in english and want to convert to some other
> > languages. as mentioned in django docs i added translation tags to my
> > templates than gived that command :
> >
> > horsel...@horselogy-pardus yerelilan $ python manage.py compilemessages
> > Error: This script should be run from the Django SVN tree or your project
> > or app tree, or with the settings module specified.
> >
> > as you see, it raised an error. why it happened like this?
> >
> > Regards
> > --
> > Mirat Can Bayrak 
>

Did you guys try it within the project directory with the projects settings 
module or set the environment DJANGO_SETTINGS_MODULE for your project, I'm a 
linux user and you would do either:

# export DJANGO_SETTINGS_MODULE=myproject.settings
# django_admin.py makemessages

For windows I believe it's:

C:\> set DJANGO_SETTINGS_MODULE=myproject.settings
C:\> django_admin.py makemessages

Mike
-- 
Kington's Law of Perforation:
If a straight line of holes is made in a piece of paper, such
as a sheet of stamps or a check, that line becomes the strongest
part of the paper.


signature.asc
Description: This is a digitally signed message part.


Re: How to generate po files ?

2009-09-09 Thread Léon Dignòn

I am glad you ask this. I was running in that problem too.
I use Windows Vista and I've run 'django-admin.py makemessages' inside
the folder I also run 'django-admin.py startproject bestsiteever'.
Same error.

-leond

On Sep 9, 7:28 pm, Mirat Can Bayrak  wrote:
> Hi, i finished my site in english and want to convert to some other 
> languages. as mentioned in django docs i added translation tags to my 
> templates than gived that command :
>
> horsel...@horselogy-pardus yerelilan $ python manage.py compilemessages
> Error: This script should be run from the Django SVN tree or your project or 
> app tree, or with the settings module specified.
>
> as you see, it raised an error. why it happened like this?
>
> Regards
> --
> Mirat Can Bayrak 
--~--~-~--~~~---~--~~
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: Choices of foreign keys?

2009-09-09 Thread Léon Dignòn

Hello Peter,

sorry, I was talking about choices, not a choice field:
http://docs.djangoproject.com/en/dev/ref/models/fields/#choices

Since any photo can only belong to one category (because I say so :) I
would tend towards using 1:N instead of M:N. Or did I missunderstand
you? If one photo can belong to several cetegories, I would use your
ManyToManyField, is that right?

You say that an object should be represented as a table in SQL. I know
that, too. But the choices I mentioned above, are confusing me. Can
you explain me why they exist, or give me a good example that justify
choices?

-leond


On Sep 9, 6:36 pm, Peter Coles  wrote:
> Hey Léon,
>
> ChoiceField is a form field, not a table column—maybe you're thinking
> about CommaSeparatedIntegerField? You could use that and hardcode
> which categories represent which ids in your python 
> code.http://docs.djangoproject.com/en/dev/ref/models/fields/#commaseparate...
>
> On the other hand, the standard way of representing an object and its
> categories in SQL is to use a ManyToMany relation. This approach
> easily handles everything you want to do in a much easier to manage
> format, and it's unlikely that you'll need to worry about "bloat"—
> optimizing how you serve web pages, static files, caching, etc. will
> give you *many* more gains than holding off from adding another table
> to your db.
>
> To setup your category, you can add something like this to your models
> file (above your photos model):
>
> class Category(models.Model):
>     title = models.CharField(max_length=100)
>     slug = models.SlugField(unique=True)
>     class Admin:
>         pass
>
> and then inside your photos model add a new column:
>
>     categories = models.ManyToManyField(Category, blank=True)
>
> -Peter
>
> On Sep 9, 11:54 am, Léon Dignòn  wrote:
>
>
>
> > Hello,
>
> > let's assume we have a model for photos with the fields id, user,
> > photo. Any user should be able to categorize his foto with a given
> > number of categories, e.g. person, car, building. In future it's
> > possible that I add more categories.
>
> > My question is whether the new category field should be a ChoiceField,
> > or a ForeignKey?
>
> > I would prefer a ChoiceField because
> > - I am 99% sure that there won't be new categories.
> > - the only person who maybe adds a new category will be me.
> > - another model would bloat up my database and my models.py
>
> > But maybe I should use a ForeignKey because,
> > - I don't have to edit the model/table.
> > - it's easier to add a choice to a table than in the source code.
> > - because values in databases should be atomic.
>
> > Otherwise, assuming that syncdb can't handle adding new choices to an
> > existing table, adding a choice directly in the database application
> > (MySQL, PostgreSQL) is no problem. Removing a choice won't happen.- Hide 
> > quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



How to generate po files ?

2009-09-09 Thread Mirat Can Bayrak

Hi, i finished my site in english and want to convert to some other languages. 
as mentioned in django docs i added translation tags to my templates than gived 
that command :

horsel...@horselogy-pardus yerelilan $ python manage.py compilemessages
Error: This script should be run from the Django SVN tree or your project or 
app tree, or with the settings module specified.

as you see, it raised an error. why it happened like this? 

Regards 
-- 
Mirat Can Bayrak 

--~--~-~--~~~---~--~~
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: Unique fields that allow nulls

2009-09-09 Thread Karen Tracey
On Wed, Sep 9, 2009 at 12:37 PM, Jan Ostrochovsky <
jan.ostrochov...@gmail.com> wrote:

>
>
> But I see as an ultimate solution to distinguish between NULL and
> empty string for CharField and TextField, as I see it, here is reason
> to have it.
>
> NULL means undefined (or unknown) value, and its Python equivalent is
> probably None.
> ´´ - empty string - means defined value (and that value is empty
> string), and its Python equivalent is empty string.
>
> We can found many many examples, where some entity has some parameter
> defined and in that case it must be unique, or it is not defined at
> all.
>
>
Django's general philosophy is that there should be only one "blank" value
for character fields, see:

http://docs.djangoproject.com/en/dev/ref/models/fields/#null

I don't see that fundamentally changing.  Nor do I see the choice being
changed from empty string to NULL -- it's far to late for a change like
that.

I see this unique if specified requirement as "an excellent reason"
mentioned in that doc to go against the general recommendation to not set
null=True on char fields. If there is some clean way to make this particular
case work in Django without requiring the user to create custom forms with
custom clean methods, then that might be implemented to fix ticket #4136.
But I haven't heard a proposal that accomplishes handling this case without
changing the default behavior...

Karen

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



how to use the generic_inline_formset_factory?

2009-09-09 Thread Viktor

hi,

how can I create a page similar to the admin pages in the sense of
having a ModelForm and a formset generated with
generic_inline_formset_factory, that is model instances related to my
"base" model with the content_types framework?

I have two models:

class Project(models.Model):

title = models.CharField(max_length=255)
customer = models.ForeignKey(User)
language_from = models.ForeignKey(Language,
related_name='language_from')
language_to = models.ForeignKey(Language,
related_name='language_to')
deadline = models.DateTimeField(null=True)
revenue = models.OneToOneField(Revenue, null=True)
comment = models.TextField(blank=True)
accepted = models.BooleanField(default=False)
closed = models.BooleanField(default=False)
created = models.DateTimeField(auto_now_add=True)
files = generic.GenericRelation('File')

class File(models.Model):

content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()

file = models.FileField(upload_to=get_file_upload_to)
comment = models.TextField(blank=True)
created = models.DateTimeField(auto_now_add=True)

and a form

class ProjectForm(forms.ModelForm):

customer = forms.IntegerField(widget=forms.HiddenInput, initial=0)

class Meta:
model = models.Project
exclude = ['revenue', 'closed', 'accepted']

I can create a form wizard, and add ProjectForm at its first page, and
the following formset at the second

ProjectFilesFormSet = generic_inlineformset_factory(models.File,
exclude=['created'], can_delete=False)

but how can I do it on one page? I'm sure that I miss something, as
ProjectFilesFormSet by default is a subclass of
BaseGenericInlineFormSet, thus it should be possible to be used
"inline".

Can I combine an instance of ProjectFrom and ProjectFilesFormSet on
the same page? Should I do it in the view function by calling first
myProjectForm.save and then ProjectFiledFormSet.save, or is there a
better way?
If so, how can I assure that the ProjectForm won't get written to the
database until the Files are saved?

I know these are quite a few question, and I would be happy to get
answers even to a subset of them.

Thank you, Viktor
--~--~-~--~~~---~--~~
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: Custom url in django Django sitemap

2009-09-09 Thread Peter Coles

Hi eli,

If you want serve a "static file" (that never changes and doesn't take
advantage of django's template system) then you shouldn't be serving
it with django.  You can use django if you really want:
http://docs.djangoproject.com/en/dev/howto/static-files/ but you're
better off having your server (like apache) handle it directly:
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id1

However, you may want your about-me page to inherit a header and
footer or other stuff from a base template (if you don't know what I'm
talking about read this: 
http://docs.djangoproject.com/en/dev/intro/overview/#intro-overview
) -- if that's the case, you can use the direct_to_template generic
view as described here:

http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-simple-direct-to-template

-Peter

On Sep 9, 11:41 am, eli  wrote:
> Hi,
>
> How to add custom static url (they are not in database) to Django
> Sitemap? for ex: /about-me.html, /contact.html, /some-static-url.html
>
> regards.
--~--~-~--~~~---~--~~
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: Unique fields that allow nulls

2009-09-09 Thread Jan Ostrochovsky

Karen, thanks for useful workaround.

Another (but little bit sick) workaround I see is to create separate
class for such field, and an optional OneToOneField to that class...

But I see as an ultimate solution to distinguish between NULL and
empty string for CharField and TextField, as I see it, here is reason
to have it.

NULL means undefined (or unknown) value, and its Python equivalent is
probably None.
´´ - empty string - means defined value (and that value is empty
string), and its Python equivalent is empty string.

We can found many many examples, where some entity has some parameter
defined and in that case it must be unique, or it is not defined at
all.

On Sep 9, 4:35 pm, Karen Tracey  wrote:
> On Wed, Sep 9, 2009 at 9:14 AM, Jan Ostrochovsky 
> > wrote:
>
> > Hello,
>
> > I have the exact need, as author of this question:
>
> >http://stackoverflow.com/questions/454436/unique-fields-that-allow-nu...
> > .
>
> I answered on that question because the answer that was there was incorrect.
>
> > I want a value to be unique, if it is not NULL. Database backend
> > allows such construction, but in Django admin I have got this error
> > message when saving form: Business unit with this VAT id already
> > exists.
>
> > As I see it, Django admin is storing empty string (''), and not NULL,
> > as documented here:
> >http://docs.djangoproject.com/en/dev/ref/models/fields/#null,
> > and that is the root cause - empty string is not NULL.
>
> Correct, this is the problem.
>
> > 
>
> > As I found later, this problem is (or was?) discussed also here:
> >http://code.djangoproject.com/ticket/4136.
>
> > Is there any progress in that area? (Some best practise howto...)
>
> > Thanks in advance, any advice is welcome.
>
> I don't know if that ticket will ever be fixed.  In general Django wants to
> store an empty string, not NULL, for empty character fields.  That is not
> going to change and nobody in that ticket has come up with a way to change
> it just for this particular case.
>
> You can work around the existing behavior in your own code by telling admin
> to use a custom form with a custom clean method for the field in question
> which turns the blank string into None.  Then NULLs will be stored in the
> DB, and they willl not compare the same for uniqueness checks.
>
> Karen
--~--~-~--~~~---~--~~
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: Choices of foreign keys?

2009-09-09 Thread Peter Coles

Hey Léon,

ChoiceField is a form field, not a table column—maybe you're thinking
about CommaSeparatedIntegerField? You could use that and hardcode
which categories represent which ids in your python code.
http://docs.djangoproject.com/en/dev/ref/models/fields/#commaseparatedintegerfield

On the other hand, the standard way of representing an object and its
categories in SQL is to use a ManyToMany relation. This approach
easily handles everything you want to do in a much easier to manage
format, and it's unlikely that you'll need to worry about "bloat"—
optimizing how you serve web pages, static files, caching, etc. will
give you *many* more gains than holding off from adding another table
to your db.

To setup your category, you can add something like this to your models
file (above your photos model):

class Category(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField(unique=True)
class Admin:
pass

and then inside your photos model add a new column:

categories = models.ManyToManyField(Category, blank=True)


-Peter

On Sep 9, 11:54 am, Léon Dignòn  wrote:
> Hello,
>
> let's assume we have a model for photos with the fields id, user,
> photo. Any user should be able to categorize his foto with a given
> number of categories, e.g. person, car, building. In future it's
> possible that I add more categories.
>
> My question is whether the new category field should be a ChoiceField,
> or a ForeignKey?
>
> I would prefer a ChoiceField because
> - I am 99% sure that there won't be new categories.
> - the only person who maybe adds a new category will be me.
> - another model would bloat up my database and my models.py
>
> But maybe I should use a ForeignKey because,
> - I don't have to edit the model/table.
> - it's easier to add a choice to a table than in the source code.
> - because values in databases should be atomic.
>
> Otherwise, assuming that syncdb can't handle adding new choices to an
> existing table, adding a choice directly in the database application
> (MySQL, PostgreSQL) is no problem. Removing a choice won't happen.
--~--~-~--~~~---~--~~
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: foreign key not generated when pointing to a model in another application

2009-09-09 Thread Daniel Roseman

On Sep 9, 5:29 pm, jim  wrote:
> Am using sqlite3 and django version 1.0
>
> class U(models.Model):
>     woid = models.ForeignKey('workorder.X')
>
> In the workorder app I have:
>
> class X(models.Model):
>     woid = models.CharField(max_length=20, primary_key=True)
>
> When I try :
>
> python manage.py sql ceuser
>
> I get
>
> CREATE TABLE "ceuser_u" (
>     "id" integer NOT NULL PRIMARY KEY,
>     "woid_id" varchar(20) NOT NULL
> )
> ;
>
> As can be seen, the class ceuser does not have the FOREIGN KEY
> constraint...
>
> seen some threads abut it but no solution...

Sqlite does not support foreign key constraints. See
http://www.sqlite.org/omitted.html
--
DR
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



foreign key not generated when pointing to a model in another application

2009-09-09 Thread jim

Am using sqlite3 and django version 1.0


class U(models.Model):
woid = models.ForeignKey('workorder.X')


In the workorder app I have:

class X(models.Model):
woid = models.CharField(max_length=20, primary_key=True)


When I try :

python manage.py sql ceuser


I get

CREATE TABLE "ceuser_u" (
"id" integer NOT NULL PRIMARY KEY,
"woid_id" varchar(20) NOT NULL
)
;


As can be seen, the class ceuser does not have the FOREIGN KEY
constraint...

seen some threads abut it but no solution...


--~--~-~--~~~---~--~~
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: Incorrect {{root_path}} in classes derived from AdminSite

2009-09-09 Thread Vlastimil Zima

Neither name nor app_label fixed situation.
AdminSite instance django.contrib.admin.site is constructed without
any names and it works.
In documentation is written: "If no instance name is provided, a
default instance name of admin will be used."

On Sep 9, 5:31 pm, Ramiro Morales  wrote:
> On Wed, Sep 9, 2009 at 4:33 AM, Vlastimil Zima  
> wrote:
>
> > Hello,
> > I found out, that if I made derived class of
> > django.contrib.admin.sites.AdminSite admin generated by this AdminSite
> > in unable to to create correct links e.g. for Logout (http://
> > 127.0.0.1:8000/admin/Nonelogout/), Change Password (http://
> > 127.0.0.1:8000/admin/Nonepassword_change/), etc. (examples are from
> > index page). I am not sure whether it is mistake at my site or
> > somewhere else.
>
> > Everything I changed since createproject and syncdb:
>
> > - add 'django.contrib.admin' to INSTALLED_APPS
> > - create sites.py :
>
> > from django.contrib.admin.sites import AdminSite
>
> > class TestAdminSite(AdminSite):
> >   def get_urls(self):
> >       """
> >       So far call super.get_urls, prepared for extensions
> >       """
> >       urlpatterns = []
> >       urlpatterns.extend( super(TestAdminSite, self).get_urls() )
> >       return urlpatterns
> >     def urls(self):
> >       return self.get_urls()
> >   urls = property(urls)
>
> > admin_site = TestAdminSite()
>
> You need to provide a name parameter to the constructor of your AdminSite
> sub-class as described in the relevant Django 1.1 admin app documentation:
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adminsite-obj...http://docs.djangoproject.com/en/dev/ref/contrib/admin/#multiple-admi...
>
>
>
> > - generate admin in urls.py :
>
> > from django.conf.urls.defaults import *
> > from sites import admin_site
> > urlpatterns = patterns('',
> >   (r'^admin/', include(admin_site.urls)),
> > )
>
> > Although there are no registered models, it can be observed that links
> > are not correct.
>
> > Any idea how to solve this problem or confirm that it is a bug will be
> > helpful.
>
> --
> Ramiro Moraleshttp://rmorales.net
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Choices of foreign keys?

2009-09-09 Thread Léon Dignòn

Hello,

let's assume we have a model for photos with the fields id, user,
photo. Any user should be able to categorize his foto with a given
number of categories, e.g. person, car, building. In future it's
possible that I add more categories.

My question is whether the new category field should be a ChoiceField,
or a ForeignKey?

I would prefer a ChoiceField because
- I am 99% sure that there won't be new categories.
- the only person who maybe adds a new category will be me.
- another model would bloat up my database and my models.py

But maybe I should use a ForeignKey because,
- I don't have to edit the model/table.
- it's easier to add a choice to a table than in the source code.
- because values in databases should be atomic.

Otherwise, assuming that syncdb can't handle adding new choices to an
existing table, adding a choice directly in the database application
(MySQL, PostgreSQL) is no problem. Removing a choice won't happen.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Nested Inlines / Multiple ManyToMany field admin support

2009-09-09 Thread Mike W.

Hey guys.  I looked around this group & the web for an answer to this
question, but I can't seem to find one.

My application has Publications, which have multiple Authors. Each
Author has one Person, but each Auther can have multiple
Institutions.  (This is an app to keep track of academic publications,
for some background info). See my (abbreviated) models towards the
end.

I want to use the custom admin, but I can't seem to get it to work
with the Nested ManyToManyFields.  I can get it to inline the Author
field inside the Publication admin, but I also want to be able to edit
each Author's institutions from the publication admin. Is this
possible?  In other words, does Admin support ManyToMany fields inside
of an Inline adminmodel?

Thanks much,
Mike

Models below-


So we have it set up like this:

class Publication(Unit):
title = models.CharField(max_length=200)
authors = models.ManyToManyField
(Person,blank=True,null=True,through="Author")

class Institution(models.Model):
name = models.CharField(max_length=200)
location = models.ForeignKey(Location, blank=True, null=True)

class Author(models.Model):
person = models.ForeignKey(Person)
publication = models.ForeignKey(Publication)
order = models.PositiveIntegerField(blank=True,null=True)
institutes = models.ManyToManyField
(Institution,blank=True,null=True,through="AuthorInstitutes")

class AuthorInstitutes(models.Model):
institute = models.ForeignKey(Institution)
author = models.ForeignKey(Author)
rank = models.CharField(max_length=3, choices=RANK_CHOICES)

class Person(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
middle_name = models.CharField(max_length=100,blank=True,null=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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ModelAdmins for abstract model and its children

2009-09-09 Thread Aaron

I have an abstract base model as well several models that subclass it.
Now I am figuring out how to design the ModelAdmin subclasses for
these models.

I need a ModelAdmin that can display the fields of the base model (so
that the ModelAdmins for the child models don't have to do that
themselves) as well as perform certain operations when saving a model
that must be done by all of the child models. I've come up with a
ModelAdmin subclass that works with the abstract base model, but am
unsure how to properly subclass it for the child models.

Specifically, I'm unsure how to handle properties like fieldsets,
inlines, and list_display. These would be properties I'd set in the
base ModelAdmin to ensure that the common information provided by the
base model is available in all the models. But if I set those
properties in the ModelAdmin subclasses for the child models I would
be overriding the information set by the base model's ModelAdmin.

The best way around this is to use an append instead of an assignment
("+=" instead of "=") when configuring these properties in the child
model ModelAdmins. Would this be my best bet?

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



Custom url in django Django sitemap

2009-09-09 Thread eli

Hi,

How to add custom static url (they are not in database) to Django
Sitemap? for ex: /about-me.html, /contact.html, /some-static-url.html

regards.
--~--~-~--~~~---~--~~
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: Incorrect {{root_path}} in classes derived from AdminSite

2009-09-09 Thread Ramiro Morales

On Wed, Sep 9, 2009 at 4:33 AM, Vlastimil Zima  wrote:
>
> Hello,
> I found out, that if I made derived class of
> django.contrib.admin.sites.AdminSite admin generated by this AdminSite
> in unable to to create correct links e.g. for Logout (http://
> 127.0.0.1:8000/admin/Nonelogout/), Change Password (http://
> 127.0.0.1:8000/admin/Nonepassword_change/), etc. (examples are from
> index page). I am not sure whether it is mistake at my site or
> somewhere else.
>
> Everything I changed since createproject and syncdb:
>
> - add 'django.contrib.admin' to INSTALLED_APPS
> - create sites.py :
>
> from django.contrib.admin.sites import AdminSite
>
> class TestAdminSite(AdminSite):
>   def get_urls(self):
>       """
>       So far call super.get_urls, prepared for extensions
>       """
>       urlpatterns = []
>       urlpatterns.extend( super(TestAdminSite, self).get_urls() )
>       return urlpatterns
>     def urls(self):
>       return self.get_urls()
>   urls = property(urls)
>
> admin_site = TestAdminSite()

You need to provide a name parameter to the constructor of your AdminSite
sub-class as described in the relevant Django 1.1 admin app documentation:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adminsite-objects
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#multiple-admin-sites-in-the-same-urlconf

>
> - generate admin in urls.py :
>
> from django.conf.urls.defaults import *
> from sites import admin_site
> urlpatterns = patterns('',
>   (r'^admin/', include(admin_site.urls)),
> )
>
> Although there are no registered models, it can be observed that links
> are not correct.
>
> Any idea how to solve this problem or confirm that it is a bug will be
> helpful.
>

-- 
Ramiro Morales
http://rmorales.net

--~--~-~--~~~---~--~~
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: Custom template tags

2009-09-09 Thread Daniel Roseman

On Sep 9, 4:00 pm, tdelam  wrote:
> Hey,
>
> I would like to know if I should write a custom template tag or if
> anyone can give me some direction on how to do the following:
>
> 1) User visits a page on a web site, example.org/campaign/businessname
> 2) I capture "businessname" and fetch the details of that user from
> the database and render a page addressed specifically to him/her.
>
> My problem is that we are using TinyMCE to input the content for that
> "businessname". Throughout the body of the content the persons name
> and email address should be rendered on the page, I am looking to do
> something like the following:
>
> Lorem ipsum dolor sit amet, consectetur adipiscing elit.
> {{ business.firstname }}, praesent massa dui, rutrum vel scelerisque
> ut, consequat sed sem. Duis dapibus {{ business.email}}, nisl viverra
> odio eleifend non lacinia odio suscipit. Aliquam vestibulum dui vel
> leo dictum sollicitudin dictum magna bibendum. Pellentesque sed nisl a
> metus ornare rutrum eu sagittis est.
>
> The problem with the above paragraph is that tinymce cannot accept
> template tags. Is there anyway I can use template tags inside tinymce
> content? I am guessing no.. what would be the best approach for this?

A template tag could deal with this. What you would need to do in your
tag would be to instantiate a django.template.Template class with the
content of your field, and render that against the current context.
It's not trivial (you won't be able to use any of the shortcut
decorators) but should be doable.
--
DR.
--~--~-~--~~~---~--~~
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: Sourcing java script file inside django

2009-09-09 Thread Hrishikesh Dhayagude

Thank u very much.. it worked..
Regards,
Hrishikesh Dhayagude

On Sep 8, 11:38 pm, Ulysses Almeida 
wrote:
> Hi,
> On Tue, 8 Sep 2009 10:59:11 -0700 
> (PDT),HrishikeshDhayagude wrote:
>
> > Hi,
> [cut]
> > If i want to source abc.js then
> >  
> [cut]
> > So do i need to include any action to be performed on that particular
> > url in url.py??
>
>   Yes, this abc.js is a static file. You should setup your django do serve
> static files.
>   Readhttp://docs.djangoproject.com/en/dev/howto/static-files/for a full
> explanation. If stay in doubts after reading, let us know.
>
> [cut]
>
>   Best regards.
>
> --
> Ulysses Almeida
> Analista Judiciário - Análise de Sistemas
> Secretaria de Tecnologia da Informação - COINF - TRE-MS
> ulysses.alme...@tre-ms.gov.br
--~--~-~--~~~---~--~~
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: MySQL-Python and Snow Leopard

2009-09-09 Thread Walter Scheper
Brandon Taylor wrote:
[snip]

> However, I can't get MySQL-Python 1.2.3c1 to compile. I have re-
> installed Xcode for 10.6, but I get an error trace a mile long, ending
> with error: Setup script exited with error: command 'gcc' failed with
> exit status 1
> 

Hey Brandon,

The new version of Xcode that comes with 10.6 no longer includes the 
10.4 SDK by default, which is causing problems for a lot of applications 
that expect it to be there. Without seeing your gcc error trace, I can't 
be sure this is your problem, but that's my best guess. Check your error 
trace and see if Xcode is complaining that it can't find MacOSX10.4u.sdk.

If that is your problem, then you need to re-install Xcode and select 
Mac OS X 10.4 Support on the Custom Install page.

Hope this helps,
Walter Scheper

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

<>

Custom template tags

2009-09-09 Thread tdelam

Hey,

I would like to know if I should write a custom template tag or if
anyone can give me some direction on how to do the following:

1) User visits a page on a web site, example.org/campaign/businessname
2) I capture "businessname" and fetch the details of that user from
the database and render a page addressed specifically to him/her.

My problem is that we are using TinyMCE to input the content for that
"businessname". Throughout the body of the content the persons name
and email address should be rendered on the page, I am looking to do
something like the following:

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
{{ business.firstname }}, praesent massa dui, rutrum vel scelerisque
ut, consequat sed sem. Duis dapibus {{ business.email}}, nisl viverra
odio eleifend non lacinia odio suscipit. Aliquam vestibulum dui vel
leo dictum sollicitudin dictum magna bibendum. Pellentesque sed nisl a
metus ornare rutrum eu sagittis est.

The problem with the above paragraph is that tinymce cannot accept
template tags. Is there anyway I can use template tags inside tinymce
content? I am guessing no.. what would be the best approach for this?
--~--~-~--~~~---~--~~
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: Link for new page

2009-09-09 Thread Ajit jena
Hi ,

I have one question plz help me.

I am create a page and it is showing , when I am redirect from view.py page.

In *url.py* page I have written

urlpatterns = patterns('',
(r'^$', login_page),
(r'^abc/', main_page),

)

*In view.py:*

from django.http import HttpResponse

def main_page(request):
output = '''

%s



%s
%s
Enter your Name : 
Emp id : 
Email id : 
mob : 
DOB :  (dd/mm/)
 


For more information
http://www.mindfiresolutions.com";
target='_blank'> Click here


''' % ('Application page', 'Welcome to Django Group',
   'Employee Details')
return HttpResponse(output)

def login_page(request):
login = '''

Login


Web on  webs...

Username : 
Password : 



New user Forget password?



'''
return HttpResponse(login)

def aa_page(request):

login = '''

Success


Log in Successfully!!!



'''
return HttpResponse(login)




But I want to see the page when I click the Forget password? link.(Forget password? in  login_page
method of view.py page)
But it shows the main_page data from view.py file.

Is there any setting required. I think It is a silly question. But please
help me.


Thanks,
 Ajit

On Wed, Sep 9, 2009 at 8:19 PM, Ajit jena wrote:

> thanks Peter,
>
>
>
>
> On Wed, Sep 9, 2009 at 2:28 AM, Peter Coles  wrote:
>
>>
>> Make yourself familiar with the django documention page—if you know
>> where to look for stuff there, you'll find it to be a very handy
>> resource. http://docs.djangoproject.com/en/dev/
>>
>> > 1: How can I go to next page when i submit the data in index page(log
>> > in page)
>>
>>
>> http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponseRedirect
>>
>> > 2: How can I link a page with a text. so that when I click on the text
>> > It will so the page I want.
>>
>> This sounds like you're trying to just put a link on a page? of the
>> format Click this link? The following will
>> show you the best way to generate the url for the "_url_here_" part:
>>
>> http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url
>> You should really give this a read too, naming url patterns can be
>> very convenient:
>> http://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns
>>
>> Finally, you should really read the content provided under "First
>> Steps" on the doc page: http://docs.djangoproject.com/en/dev/#first-steps
>> Especially the intro overview
>> http://docs.djangoproject.com/en/dev/intro/overview/#intro-overview
>> and then the tutorials
>>
>> >
>> > Can any one give some tips (which may face silly issues while create
>> > simple web application)
>> >
>> > Please help me to for gaining knowledge about django framework.
>> >
>> > many many thanks in advance for 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Link for new page

2009-09-09 Thread Ajit jena
thanks Peter,



On Wed, Sep 9, 2009 at 2:28 AM, Peter Coles  wrote:

>
> Make yourself familiar with the django documention page—if you know
> where to look for stuff there, you'll find it to be a very handy
> resource. http://docs.djangoproject.com/en/dev/
>
> > 1: How can I go to next page when i submit the data in index page(log
> > in page)
>
>
> http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponseRedirect
>
> > 2: How can I link a page with a text. so that when I click on the text
> > It will so the page I want.
>
> This sounds like you're trying to just put a link on a page? of the
> format Click this link? The following will
> show you the best way to generate the url for the "_url_here_" part:
>
> http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url
> You should really give this a read too, naming url patterns can be
> very convenient:
> http://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-patterns
>
> Finally, you should really read the content provided under "First
> Steps" on the doc page: http://docs.djangoproject.com/en/dev/#first-steps
> Especially the intro overview
> http://docs.djangoproject.com/en/dev/intro/overview/#intro-overview
> and then the tutorials
>
> >
> > Can any one give some tips (which may face silly issues while create
> > simple web application)
> >
> > Please help me to for gaining knowledge about django framework.
> >
> > many many thanks in advance for 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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: understsanding views

2009-09-09 Thread mettwoch

That function should at least return somewhere, I guess to the caller
which might be a "view" function that returns a HttpResponse.

Anyway, You should consider putting code that updates the database in
the "model".

Marc

On Sep 9, 4:25 pm, elminio  wrote:
> Hello,
>
> I assume that each view should return Httpresponse. What when I just
> want to execute function which updates my databes and doesnt redirect
> anywhere ?
>
> thanks for reply
--~--~-~--~~~---~--~~
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: understsanding views

2009-09-09 Thread Javier Guerra

On Wed, Sep 9, 2009 at 9:25 AM, elminio wrote:
> I assume that each view should return Httpresponse. What when I just
> want to execute function which updates my databes and doesnt redirect
> anywhere ?

the HTTP client is still waiting for some response.  usually i do an
HttpRedirect() to the updated object's get_absolute_url()

-- 
Javier

--~--~-~--~~~---~--~~
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: Unique fields that allow nulls

2009-09-09 Thread Karen Tracey
On Wed, Sep 9, 2009 at 9:14 AM, Jan Ostrochovsky  wrote:

>
> Hello,
>
> I have the exact need, as author of this question:
>
> http://stackoverflow.com/questions/454436/unique-fields-that-allow-nulls-in-django
> .
>
>
I answered on that question because the answer that was there was incorrect.


> I want a value to be unique, if it is not NULL. Database backend
> allows such construction, but in Django admin I have got this error
> message when saving form: Business unit with this VAT id already
> exists.
>
> As I see it, Django admin is storing empty string (''), and not NULL,
> as documented here:
> http://docs.djangoproject.com/en/dev/ref/models/fields/#null,
> and that is the root cause - empty string is not NULL.
>
>
Correct, this is the problem.


> 
>
> As I found later, this problem is (or was?) discussed also here:
> http://code.djangoproject.com/ticket/4136.
>
> Is there any progress in that area? (Some best practise howto...)
>
> Thanks in advance, any advice is welcome.
>
>
I don't know if that ticket will ever be fixed.  In general Django wants to
store an empty string, not NULL, for empty character fields.  That is not
going to change and nobody in that ticket has come up with a way to change
it just for this particular case.

You can work around the existing behavior in your own code by telling admin
to use a custom form with a custom clean method for the field in question
which turns the blank string into None.  Then NULLs will be stored in the
DB, and they willl not compare the same for uniqueness checks.

Karen

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



understsanding views

2009-09-09 Thread elminio

Hello,

I assume that each view should return Httpresponse. What when I just
want to execute function which updates my databes and doesnt redirect
anywhere ?

thanks for reply
--~--~-~--~~~---~--~~
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: login required

2009-09-09 Thread Jeff Green
I would think you could just extend the User model to store the registered
users and then check if the user is registered which would then redirect to
the survey page.

On Tue, Sep 8, 2009 at 11:30 PM, putih  wrote:

>
> hii,
>
> need your help on this matter :-
>
> 1. how to restrict user for certain page. for example :-
>
> non-register user have to register first before they can join a
> survey. after register, they login and redirect to the survey page.
> (not main page.)
>
> anyone, please advise me on this problem. seriously i didn't have any
> ideas on this matter..
>
> thanks
> >
>

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



IndexError when creating a formset

2009-09-09 Thread chewynougat

Hi,

I have instances in my code where I need to save an object with a new
pk. Then I need to create and save an inline formset using the newly
created object as the instance.

form_instance = form.save(commit=False)
form_instance.pk = None
form_instance.slug = None
form_instance.save()

CardioFormset = inlineformset_factory(activitycentre_models.Activity,
activitycentre_models.CardiovascularTraining)

cardio_form = CardioFormset(request.POST, instance=form_instance) #
This is the line that raises the IndexError exception.

Could anyone shed any light as to where I am going wrong here? It is
fine if I just save the form normally first (update).

Much appreciated for any help on this issue!

Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/code/contrib/activitycentre/
views.py", line 1711, in create_edit_event
cardio_form = InitialCardioFormset(request.POST, instance=a)
  File "/Library/Python/2.5/site-packages/django/forms/models.py",
line 446, in __init__
super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix
or self.rel_name)
  File "/Library/Python/2.5/site-packages/django/forms/models.py",
line 335, in __init__
super(BaseModelFormSet, self).__init__(**defaults)
  File "/Library/Python/2.5/site-packages/django/forms/formsets.py",
line 67, in __init__
self._construct_forms()
  File "/Library/Python/2.5/site-packages/django/forms/models.py",
line 452, in _construct_forms
super(BaseInlineFormSet, self)._construct_forms()
  File "/Library/Python/2.5/site-packages/django/forms/formsets.py",
line 76, in _construct_forms
self.forms.append(self._construct_form(i))
  File "/Library/Python/2.5/site-packages/django/forms/models.py",
line 455, in _construct_form
form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs)
  File "/Library/Python/2.5/site-packages/django/forms/models.py",
line 339, in _construct_form
kwargs['instance'] = self.get_queryset()[i]
  File "/Library/Python/2.5/site-packages/django/db/models/query.py",
line 232, in __getitem__
return list(qs)[0]
IndexError: list index out of range

--~--~-~--~~~---~--~~
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: Date Field in ModelForm

2009-09-09 Thread mettwoch

Some more info:

Windows Vista
Django 1.1Final
PostGreSQL 8.3.7
psycopg2
Python 2.5.4
mod_wsgi
Apache2.2

On Sep 9, 12:57 pm, Daniel Roseman  wrote:
> On Sep 9, 11:49 am, mettwoch  wrote:
>
>
>
> > Hi,
>
> > I don't understand why the following code produces an error (see
> > below):
>
> > >>> from django import forms
> > >>> from ishop.bo.models import Document
> > >>> d = Document.objects.get(pk=8)
> > >>> print d.date_due
> > 2009-08-28
> > >>> class df(forms.ModelForm):
> > >>>     class Meta:
> > >>>         model = Document
> > >>>         fields = ('status', 'date_due', 'number')
> > >>> f = df(instance=d)
> > >>> f.as_table()
>
> > produces the following error
> 
> > AttributeError: 'NoneType' object has no attribute 'label'
>
> > The same code works fine when removing the 'date_due' field from the
> > list of fields to be displayed.
>
> > Thanks for any hint
>
> > Marc
>
> Can you show the Document model definition, or at least the
> declaration of the date_due field?
> --
> DR.
--~--~-~--~~~---~--~~
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: haml + sass + django

2009-09-09 Thread Alex Robbins

You might look at http://sandbox.pocoo.org/clevercss/, which is python
based.

On Sep 8, 9:19 am, ThinRhino  wrote:
> Hello,
>
> I just came across haml and sass, but looks like it is built for Ruby on
> Rails.
>
> Any implementation that can work on Django?
>
> Though I also came acrosshttp://bit.ly/3el7iR, by which apache can take
> care of converting haml to html.
>
> Was looking for something where django can take care of the nitty-gritties
>
> Cheers
> ThinRhino
>
> --
> Ships are safe in the harbour
> But that is not what ships are built for
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Unique fields that allow nulls

2009-09-09 Thread Jan Ostrochovsky

Hello,

I have the exact need, as author of this question:
http://stackoverflow.com/questions/454436/unique-fields-that-allow-nulls-in-django.

I want a value to be unique, if it is not NULL. Database backend
allows such construction, but in Django admin I have got this error
message when saving form: Business unit with this VAT id already
exists.

As I see it, Django admin is storing empty string (''), and not NULL,
as documented here: 
http://docs.djangoproject.com/en/dev/ref/models/fields/#null,
and that is the root cause - empty string is not NULL.



As I found later, this problem is (or was?) discussed also here:
http://code.djangoproject.com/ticket/4136.

Is there any progress in that area? (Some best practise howto...)

Thanks in advance, any advice is welcome.

Jano
--~--~-~--~~~---~--~~
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: Open Position: Software/System Engineer....Django...

2009-09-09 Thread James

Thanks, I will post there.

On Sep 8, 4:41 pm, Jim McGaw  wrote:
> There is a site for posting Django jobs:
>
> http://djangogigs.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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Encoding question

2009-09-09 Thread Oleg Oltar
Well, I prefer to find alt tag inside my image and check that it's correct
instead of, checking that whole response contains some text.

btw, have a problem:

b = BeautifulSoap(client.get("/"))
b.find('img')["alt"]
again gives me those strange symbols


I am updating my django now. (was using 1.0)

On Wed, Sep 9, 2009 at 2:37 PM, Karen Tracey  wrote:

> On Wed, Sep 9, 2009 at 5:06 AM, Oleg Oltar  wrote:
>
>> Hi!
>>
>> One of my tests returned following text ()
>>
>> The test:
>> from django.test.client import Client
>>  c = Client()
>> resp = c.get("/")
>> resp.content
>>
>> In [25]: resp.content
>> Out[25]: '\r\n\r\n\r\n> Strict//EN"
>
> [snip]
>>
>> Is there a way I can convert it to normal readable text? (I need for
>> example to find a string of text in this response to check if my test case
>> Pass or failed)
>>
>>
> Is there some reason you can not simply use assertContains (
> http://docs.djangoproject.com/en/dev/topics/testing/#django.test.TestCase.assertContains)?
> There was a bug in this method handling unicode in responses, but that has
> been fixed in both 1.0.3 and 1.1:
>
> http://code.djangoproject.com/ticket/10183
>
> Karen
>
> >
>

--~--~-~--~~~---~--~~
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: changing model manager

2009-09-09 Thread goobee

great to hear, thanks Karen
I will check the ticket and hope

goobee
--~--~-~--~~~---~--~~
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: breadcrumb solution

2009-09-09 Thread Mike Dewhirst

Thanks David - I do :)

Cheers

M


David De La Harpe Golden wrote:
> Mike Dewhirst wrote:
>> I would like to get breadcrumbs working in a simple way. Could anyone 
>> please help?
> 
>> Is there a better way?
> 
> One thing you can do is a "pure template" based breadcrumb
> or pseudo-breadcrumb, assuming you have a template inheritance
> graph with different views rendering different templates -
> block.super is the key.  I'm sure I picked this up in a blog post
> somewhere, I didn't originate it:
> 
> *** base.html.djt:
> 
> {% block title %}EXAMPLE{% endblock %}
> and
> 
> 
>   {% block breadcrumb %}EXAMPLE{% endblock %}
> 
> 
> 
> *** child.html.djt:
> 
> {% extends "base.html.djt" %}
> 
> {% block title %}{{ block.super }} :: CHILD{% endblock %}
> 
> {% block breadcrumb %}{{ block.super }} » CHILD{% endblock %}
> 
> 
> 
> *** grandchild.html.djt:
> 
> {% extends "child.html.djt" %}
> 
> {% block title %}{{ block.super }} :: GRANDCHILD{% endblock %}
> 
> {% block breadcrumb %}{{ block.super }} » GRANDCHILD{% endblock %}
> 
> 
> 
> You get the idea.
> 
> 
> 
> > 
> 
> 


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



list_filter

2009-09-09 Thread elminio

Hello

I have model like:

class MyModelA(models.Model):
number = models.IntegerField()

class MyModel(models.Model):
my_model_a = models.ForeignKey(MyModelA)
other_field = other data ...

and now in admin:

class MyModelAdmin(admin.ModelAdmin):
list_filter = ("my_model_a")


it filters by my_model_a and it is ok. But is it possible to filter by
my_model_a.number (sth like that) ??




--~--~-~--~~~---~--~~
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: Incorrect {{root_path}} in classes derived from AdminSite

2009-09-09 Thread Vlastimil Zima

Django1.1

On Sep 9, 12:40 pm, Ramiro Morales  wrote:
> On Wed, Sep 9, 2009 at 4:33 AM, Vlastimil Zima  
> wrote:
>
> > Hello,
> > I found out, that if I made derived class of
> > django.contrib.admin.sites.AdminSite admin generated by this AdminSite
> > in unable to to create correct links e.g. for Logout (http://
> > 127.0.0.1:8000/admin/Nonelogout/), Change Password (http://
> > 127.0.0.1:8000/admin/Nonepassword_change/), etc. (examples are from
> > index page). I am not sure whether it is mistake at my site or
> > somewhere else.
>
> We'll need to know what released version or SN revision of Django you are 
> using
> to be able to help you.
>
> --
> Ramiro Moraleshttp://rmorales.net
--~--~-~--~~~---~--~~
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 admin templates not loading

2009-09-09 Thread Karen Tracey
On Wed, Sep 9, 2009 at 7:23 AM, Simon Lee  wrote:

>
> Hi All,
>
> I am following the tutorial in the Django website (writing your first
> django app) and get it to work on the development server. However,
> when I port to Apache, the admin template is not loaded and thus I
> could not get the nice Django UI with Apache. I try copying the
> default django admin templates into my project root and add the path
> to the TEMPLATE_DIRS in settings.py but still cannot get the django UI
> in the login page and the admin dashboard.
>
> Below is my settings:
>
> OS: Fedora 11
> Apache: 2.2 with mod_wsgi
> Django: 1.1
>
> [snip]
>  Settings.py
>
> [snip]
> # URL prefix for admin media -- CSS, JavaScript and images. Make sure
> to use a
> # trailing slash.
> # Examples: "http://foo.com/media/";, "/media/".
> ADMIN_MEDIA_PREFIX = '/media/'
>
> [snip]

When I typed in http://127.0.0.1:8000/myapp/admin in the browser when
> the development server runs the code. The output is perfect.
>
> When the development server is not running and I typed in
> http://localhost/myapp/admin, it prompt me the login page but without
> all the styling as before. I can login and go to the admin dashboard
> page but again the display is not with the django admin template.
>
>
Missing styling means missing CSS, and has nothing to do with templates.
The fact that the pages are getting delivered without template not found
exceptions means there is not a problem with templates (and you should un-do
copying the admin templates into your own tree as that is likely just to
cause confusion down the road.)

You need to set up your Apache server to serve the admin media files (which
will have urls starting with ADMIN_MEDIA_PREFIX).  These are static files
and so not served by Django, except when you are running the development
server there is an admin media server that automagically serves them out of
the Django source tree.  The files are located under
django/contrib/admin/media. The doc for setting up static file serving with
mod_wsgi is here:

http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/#serving-media-files

Karen

--~--~-~--~~~---~--~~
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: Encoding question

2009-09-09 Thread Karen Tracey
On Wed, Sep 9, 2009 at 5:06 AM, Oleg Oltar  wrote:

> Hi!
>
> One of my tests returned following text ()
>
> The test:
> from django.test.client import Client
>  c = Client()
> resp = c.get("/")
> resp.content
>
> In [25]: resp.content
> Out[25]: '\r\n\r\n\r\n Strict//EN"

[snip]
>
> Is there a way I can convert it to normal readable text? (I need for
> example to find a string of text in this response to check if my test case
> Pass or failed)
>
>
Is there some reason you can not simply use assertContains (
http://docs.djangoproject.com/en/dev/topics/testing/#django.test.TestCase.assertContains)?
There was a bug in this method handling unicode in responses, but that has
been fixed in both 1.0.3 and 1.1:

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

Karen

--~--~-~--~~~---~--~~
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: changing model manager

2009-09-09 Thread Karen Tracey
On Wed, Sep 9, 2009 at 4:58 AM, goobee  wrote:

>
> hi there
> django's features for handling data from a database are great.
> Unfortunately I work with a legacy database which does not quite fit
> into djangos requirements:
>
> Class Member(models.Model)
>mnum = models.ForeignKey(, primary_key=True)
>enum = models.ForeignKey(, primary_key=True)
>.
>
> --> no single id_...  as PK
>
>
> Would it be a big deal to change django to be able to handle these
> database models?
> if no, any hints where to find the 'switch' ;-)
>
>
There is no switch.  There is a ticket requesting this:

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

Karen

--~--~-~--~~~---~--~~
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 display and update selected fields from a model

2009-09-09 Thread Karen Tracey
On Wed, Sep 9, 2009 at 4:08 AM, Daniel Roseman wrote:

>
> As regards updating, Django will only update the fields that have
> changed in any case.
>

I don't believe this is true.  Only updating the fields that have changed
would require keeping track of what fields in the Python model instance have
been modified since it was created, and Django doesn't do that.
Alternatively the existing record could be read just prior to update and
compared with what's currently in the Python model to implement updating
only fields that differ, but Django doesn't do that either.  It does check
for the existence of a record with the to-be-updated model instance's
primary key, but it includes in the update call all non-pk fields in the
model.  The code involved is:
http://code.djangoproject.com/browser/django/tags/releases/1.1/django/db/models/base.py#L467
.

Running a little test in the shell and looking at the SQL queries confirms
that all fields are listed in the SQL UPDATE, not just changed ones:

>>> from django.db import connection
>>> from ttt.models import Foo
>>> x = Foo.objects.all()[0]
>>> x.i = 44
>>> x.save()
>>> from pprint import pprint
>>> pprint(connection.queries)
[{'sql': u'SELECT "ttt_foo"."id", "ttt_foo"."name", "ttt_foo"."i" FROM
"ttt_foo" LIMIT 1',
  'time': '0.010'},
 {'sql': u'SELECT (1) AS "a" FROM "ttt_foo" WHERE "ttt_foo"."id" = 1 ',
  'time': '0.000'},
 {'sql': u'UPDATE "ttt_foo" SET "name" = x, "i" = 44 WHERE "ttt_foo"."id" =
1 ',
  'time': '0.000'}]
>>>

Karen

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



Django admin templates not loading

2009-09-09 Thread Simon Lee

Hi All,

I am following the tutorial in the Django website (writing your first
django app) and get it to work on the development server. However,
when I port to Apache, the admin template is not loaded and thus I
could not get the nice Django UI with Apache. I try copying the
default django admin templates into my project root and add the path
to the TEMPLATE_DIRS in settings.py but still cannot get the django UI
in the login page and the admin dashboard.

Below is my settings:

OS: Fedora 11
Apache: 2.2 with mod_wsgi
Django: 1.1

--

Projects/App:

/var/www/mysite/
apache/
 myapp.wsgi
polls/
admin.py
__init__.py
models.py
tests.py
templates/
 admin/
  base_site.html
__init__.py
manage.py
settings.py
urls.py

--

 Settings.py

# Django settings for mysite project.

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_em...@domain.com'),
)

MANAGERS = ADMINS

DATABASE_ENGINE = 'postgresql_psycopg2'   #
'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mytestdb' # Or path to database file if
using sqlite3.
DATABASE_USER = 'postgres' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost.
Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not
used with sqlite3.

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as
your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as
not
# to load the internationalization machinery.
USE_I18N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use
a
# trailing slash if there is a path component (optional in other
cases).
# Examples: "http://media.lawrence.com";, "http://example.com/media/";
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure
to use a
# trailing slash.
# Examples: "http://foo.com/media/";, "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'rg+av$-m5%#hs47_^24c54wi!*gauqz4ya1o*^0vjo7&xh3=n&'

# List of callables that know how to import templates from various
sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/
django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/var/www/mysite/templates',
)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'mysite.polls',
'django.contrib.admin'
)

--

myapp.wsgi

import os
import sys

sys.path.append('/var/www')

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

---

urls.py

from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
)

---

When I typed in http://127.0.0.1:8000/myapp/admin in the browser when
the development server runs the code. The output is perfect.

When the development server is not running and I typed in
http://localhost/myapp/admin, it prompt me the login page but without
all the styling as before. I can login and go to the admin dashboard
page but again the display is not with the django admin template.

I try leaving the TEMPLATE_DIRS in the settings.py blank but still the
same output.

I changed the user/group for all the files/directories inside my
project to "apache" hoping that this is a permission issue but it does
not help either.

Please tell me what I am missing. Many thanks.

Simon
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Grou

Re: Date Field in ModelForm

2009-09-09 Thread mettwoch

Here is the definition of the field:

date_due   = models.DateField(auto_now_add=True)



On Sep 9, 12:57 pm, Daniel Roseman  wrote:
> On Sep 9, 11:49 am, mettwoch  wrote:
>
>
>
> > Hi,
>
> > I don't understand why the following code produces an error (see
> > below):
>
> > >>> from django import forms
> > >>> from ishop.bo.models import Document
> > >>> d = Document.objects.get(pk=8)
> > >>> print d.date_due
> > 2009-08-28
> > >>> class df(forms.ModelForm):
> > >>>     class Meta:
> > >>>         model = Document
> > >>>         fields = ('status', 'date_due', 'number')
> > >>> f = df(instance=d)
> > >>> f.as_table()
>
> > produces the following error
> 
> > AttributeError: 'NoneType' object has no attribute 'label'
>
> > The same code works fine when removing the 'date_due' field from the
> > list of fields to be displayed.
>
> > Thanks for any hint
>
> > Marc
>
> Can you show the Document model definition, or at least the
> declaration of the date_due field?
> --
> DR.
--~--~-~--~~~---~--~~
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: [Tutor] Encoding question

2009-09-09 Thread Kent Johnson

On Wed, Sep 9, 2009 at 5:06 AM, Oleg Oltar  wrote:
> Hi!
>
> One of my tests returned following text ()
>
> The test:
> from django.test.client import Client
>  c = Client()
> resp = c.get("/")
> resp.content
>
> In [25]: resp.content
> Out[25]: '\r\n\r\n\r\n Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>\r\n\r\n xmlns="http://www.w3.org/1999/xhtml";>\r\n  \r\n     http-equiv="content-type" content="text/html; charset=utf-8" />\r\n
> \r\n    \nJapanese innovation |
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f
> \xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8\n\r\n

> Is there a way I can convert it to normal readable text? (I need for example
> to find a string of text in this response to check if my test case Pass or
> failed)

resp.content.decode('string_escape') will convert it to encoded bytes.
Then another decode() with the correct encoding will get you Unicode.
I'm not sure what the correct encoding is for the second decode(),
most likely one of 'utf-8', 'utf_16_le' or 'utf_16_be'.

Kent

--~--~-~--~~~---~--~~
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: Managers in admin

2009-09-09 Thread Alasdair

I got the admin to use the models.Manager() by overriding the queryset
method in my EntryAdmin class:

class EntryAdmin(admin.ModelAdmin):
[...]
def queryset(self, request):
return Entry.objects

--~--~-~--~~~---~--~~
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: Date Field in ModelForm

2009-09-09 Thread Daniel Roseman

On Sep 9, 11:49 am, mettwoch  wrote:
> Hi,
>
> I don't understand why the following code produces an error (see
> below):
>
>
>
> >>> from django import forms
> >>> from ishop.bo.models import Document
> >>> d = Document.objects.get(pk=8)
> >>> print d.date_due
> 2009-08-28
> >>> class df(forms.ModelForm):
> >>>     class Meta:
> >>>         model = Document
> >>>         fields = ('status', 'date_due', 'number')
> >>> f = df(instance=d)
> >>> f.as_table()
>
> produces the following error

> AttributeError: 'NoneType' object has no attribute 'label'
>
> The same code works fine when removing the 'date_due' field from the
> list of fields to be displayed.
>
> Thanks for any hint
>
> Marc

Can you show the Document model definition, or at least the
declaration of the date_due field?
--
DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Date Field in ModelForm

2009-09-09 Thread mettwoch

Hi,

I don't understand why the following code produces an error (see
below):

>>> from django import forms
>>> from ishop.bo.models import Document
>>> d = Document.objects.get(pk=8)
>>> print d.date_due
2009-08-28
>>> class df(forms.ModelForm):
>>> class Meta:
>>> model = Document
>>> fields = ('status', 'date_due', 'number')
>>> f = df(instance=d)
>>> f.as_table()

produces the following error

---
AttributeErrorTraceback (most recent call
last)

C:\Users\Marc\Python\dj\ishop\ in ()

C:\Python25\lib\site-packages\django\forms\forms.pyc in as_table(self)
188 def as_table(self):
189 "Returns this form rendered as HTML s -- excluding
the ."
--> 190 return self._html_output(u'%(label)s%
(errors)s%(field)s%help_text)s', u'%s', '', u'%s', False)
191
192 def as_ul(self):

C:\Python25\lib\site-packages\django\forms\forms.pyc in _html_output
(self, normal_row, error_row, row_ender, help_text_html,
errors_on_separate_row)
140 output, hidden_fields = [], []
141 for name, field in self.fields.items():
--> 142 bf = BoundField(self, field, name)
143 bf_errors = self.error_class([conditional_escape
(error) for error in bf.errors]) # Escape and cache in local variable.
144 if bf.is_hidden:

C:\Python25\lib\site-packages\django\forms\forms.pyc in __init__(self,
form, field, name)
344 self.html_name = form.add_prefix(name)
345 self.html_initial_name = form.add_initial_prefix(name)
--> 346 if self.field.label is None:
347 self.label = pretty_name(name)
348 else:

AttributeError: 'NoneType' object has no attribute 'label'

The same code works fine when removing the 'date_due' field from the
list of fields to be displayed.

Thanks for any hint

Marc
--~--~-~--~~~---~--~~
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: breadcrumb solution

2009-09-09 Thread David De La Harpe Golden

Mike Dewhirst wrote:
> I would like to get breadcrumbs working in a simple way. Could anyone 
> please help?

> Is there a better way?

One thing you can do is a "pure template" based breadcrumb
or pseudo-breadcrumb, assuming you have a template inheritance
graph with different views rendering different templates -
block.super is the key.  I'm sure I picked this up in a blog post
somewhere, I didn't originate it:

*** base.html.djt:

{% block title %}EXAMPLE{% endblock %}
and


  {% block breadcrumb %}EXAMPLE{% endblock %}



*** child.html.djt:

{% extends "base.html.djt" %}

{% block title %}{{ block.super }} :: CHILD{% endblock %}

{% block breadcrumb %}{{ block.super }} » CHILD{% endblock %}



*** grandchild.html.djt:

{% extends "child.html.djt" %}

{% block title %}{{ block.super }} :: GRANDCHILD{% endblock %}

{% block breadcrumb %}{{ block.super }} » GRANDCHILD{% endblock %}



You get the idea.



--~--~-~--~~~---~--~~
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: Incorrect {{root_path}} in classes derived from AdminSite

2009-09-09 Thread Ramiro Morales

On Wed, Sep 9, 2009 at 4:33 AM, Vlastimil Zima  wrote:
>
> Hello,
> I found out, that if I made derived class of
> django.contrib.admin.sites.AdminSite admin generated by this AdminSite
> in unable to to create correct links e.g. for Logout (http://
> 127.0.0.1:8000/admin/Nonelogout/), Change Password (http://
> 127.0.0.1:8000/admin/Nonepassword_change/), etc. (examples are from
> index page). I am not sure whether it is mistake at my site or
> somewhere else.

We'll need to know what released version or SN revision of Django you are using
to be able to help you.

-- 
Ramiro Morales
http://rmorales.net

--~--~-~--~~~---~--~~
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: IOError: request data read error on POST, anyone solved this?

2009-09-09 Thread Graham Dumpleton



On Sep 9, 8:09 pm, "jeremias.kangas" 
wrote:
> Hi all,
>
> This error started popping on last sunday, and it keeps happening
> pretty randomly, like 1-2 times a day. I read from the internet that
> this problem seems to be pretty common, though didn't find out if
> anyone had any success solving it.
>
> My setup is WSGI+django on ubuntu. Django version is 1.0.2.
>
> Is there any possibility that this error results from my code? Or
> could I make things work by doing things differently? Currently I have
> file upload forms, and the error seems to happen during file
> uploading.
>
> Could faulty hardware be causing this? I'm running my app on home
> server, and I have lousy D-Link router between the server and
> internet. Or perhaps I could upgrade my home server to something more
> efficient?

It is because from the server perspective the client connection was
dropped before the request body had been able to be completely read.
So, shouldn't be anything wrong with the application or the server.
Can be caused by user aborting an upload explicitly, or clicking
submit button twice accidentally. Faulty networks that are dropping
connections could also be a cause.

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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



IOError: request data read error on POST, anyone solved this?

2009-09-09 Thread jeremias.kangas

Hi all,

This error started popping on last sunday, and it keeps happening
pretty randomly, like 1-2 times a day. I read from the internet that
this problem seems to be pretty common, though didn't find out if
anyone had any success solving it.

My setup is WSGI+django on ubuntu. Django version is 1.0.2.

Is there any possibility that this error results from my code? Or
could I make things work by doing things differently? Currently I have
file upload forms, and the error seems to happen during file
uploading.

Could faulty hardware be causing this? I'm running my app on home
server, and I have lousy D-Link router between the server and
internet. Or perhaps I could upgrade my home server to something more
efficient?

- Jeremias
--~--~-~--~~~---~--~~
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: formatting dates for DateTimeField()

2009-09-09 Thread Gonzalo

I thought that was the case, Thanks for your reply.

G.

On Sep 9, 10:33 am, Daniel Roseman  wrote:
> On Sep 9, 9:21 am, Gonzalo  wrote:
>
> > How would you store that into the database, what type of field on the
> > model I mean? should I store the number of seconds + number of days in
> > seconds? or the datetime.timedelta() object?
>
> > Thanks
>
> You can't store a timedelta object in a database. And annoyingly,
> there's no simple method to convert a timedelta to seconds. You have
> to do it manually:
> time_diff_seconds = time_diff.days * 86400 + time_diff.seconds
>
> So now you have a value in seconds you can store in an IntegerField.
> --
> DR.
--~--~-~--~~~---~--~~
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: Encoding question

2009-09-09 Thread Oleg Oltar
It's more then great!

Thanks!

2009/9/9 ray 

>
> Hi Oleg
>
> You can use BeautifulSoup
>
> from BeautifulSoup import BeautifulSoup
> >>> html = '\r\n\r\n\r\n Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>\r\n\r\n xmlns="http://www.w3.org/1999/xhtml";>\r\n  \r\n http-equiv="content-type" content="text/html; charset=utf-8" />\r\n\r\n
>\nJapanese innovation |
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f
> \xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8\n\r\n
>\n content="\xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> \xd0\xa2\xd0\xb5\xd1\x85\xd0\xbd\xd0\xbe\xd0\xbb\xd0\xbe\xd0\xb3\xd0\xb8\xd0\xb8,
> \xd0\x98\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8,
> \xd0\x94\xd0\xbe\xd0\xbc\xd0\xb0\xd1\x88\xd0\xbd\xd1\x8f\xd1\x8f
> \xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x86\xd0\xb0" />\n name="description"
> content="\xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> \xd1\x8f\xd0\xbf\xd0\xbe\xd0\xbd\xd1\x81\xd0\xba\xd0\xb8\xd0\xb5
> \xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8,
> \xd1\x8f\xd0\xbf\xd0\xbe\xd0\xbd\xd1\x81\xd0\xba\xd0\xb8\xd0\xb5
> \xd1\x82\xd0\xb5\xd1\x85\xd0\xbd\xd0\xbe\xd0\xbb\xd0\xbe\xd0\xb3\xd0\xb8\xd0\xb8,
> \xd0\xbd\xd0\xb0\xd1\x83\xd0\xba\xd0\xb0
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd0\xb8,
> \xd1\x83\xd1\x87\xd0\xb5\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> \xd0\xba\xd0\xbe\xd0\xbc\xd0\xbf\xd0\xb0\xd0\xbd\xd0\xb8\xd0\xb8
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> \xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x80\xd1\x8b
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f" />\n\r\n\r\n'
> >>> soup = BeautifulSoup(html)
> >>> print soup.prettify()
>  www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> http://www.w3.org/1999/xhtml";>
>  
>>
>   
>   Japanese innovation | Япония инновации
>  
>  
>  
>  
> 
>
> best wishes
>
> Ray McBride
>
> On 9 Sep, 10:06, Oleg Oltar  wrote:
> > Hi!
> >
> > One of my tests returned following text ()
> >
> > The test:
> > from django.test.client import Client
> >  c = Client()
> > resp = c.get("/")
> > resp.content
> >
> > In [25]: resp.content
> > Out[25]: '\r\n\r\n\r\n > Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
> ">\r\n\r\n > xmlns="http://www.w3.org/1999/xhtml";>\r\n  \r\n > http-equiv="content-type" content="text/html; charset=utf-8" />\r\n
> > \r\n\nJapanese innovation |
> > \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f
> >
> \xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8\n\r\n
> > \n > content="\xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> >
> \xd0\xa2\xd0\xb5\xd1\x85\xd0\xbd\xd0\xbe\xd0\xbb\xd0\xbe\xd0\xb3\xd0\xb8\xd0\xb8,
> > \xd0\x98\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8,
> > \xd0\x94\xd0\xbe\xd0\xbc\xd0\xb0\xd1\x88\xd0\xbd\xd1\x8f\xd1\x8f
> > \xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x86\xd0\xb0"
> />\n > name="description"
> > content="\xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> > \xd1\x8f\xd0\xbf\xd0\xbe\xd0\xbd\xd1\x81\xd0\xba\xd0\xb8\xd0\xb5
> > \xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8,
> > \xd1\x8f\xd0\xbf\xd0\xbe\xd0\xbd\xd1\x81\xd0\xba\xd0\xb8\xd0\xb5
> >
> \xd1\x82\xd0\xb5\xd1\x85\xd0\xbd\xd0\xbe\xd0\xbb\xd0\xbe\xd0\xb3\xd0\xb8\xd0\xb8,
> > \xd0\xbd\xd0\xb0\xd1\x83\xd0\xba\xd0\xb0
> > \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd0\xb8,
> > \xd1\x83\xd1\x87\xd0\xb5\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5
> > \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> > \xd0\xba\xd0\xbe\xd0\xbc\xd0\xbf\xd0\xb0\xd0\xbd\xd0\xb8\xd0\xb8
> > \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> > \xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x80\xd1\x8b
> > \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f" />\n\r\n\r\n
> >
> > Is there a way I can convert it to normal readable text? (I need for
> example
> > to find a string of text in this response to check if my test case Pass
> or
> > failed)
> >
>

--~--~-~--~~~---~--~~
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: Encoding question

2009-09-09 Thread ray

Hi Oleg

You can use BeautifulSoup

from BeautifulSoup import BeautifulSoup
>>> html = '\r\n\r\n\r\n>> Strict//EN" 
>>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>\r\n\r\n>> xmlns="http://www.w3.org/1999/xhtml";>\r\n  \r\n>> http-equiv="content-type" content="text/html; charset=utf-8" />\r\n\r\n 
>>>\nJapanese innovation | 
>>> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f 
>>> \xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8\n\r\n
>>> \n>> content="\xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f, 
>>> \xd0\xa2\xd0\xb5\xd1\x85\xd0\xbd\xd0\xbe\xd0\xbb\xd0\xbe\xd0\xb3\xd0\xb8\xd0\xb8,
>>>  \xd0\x98\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8, 
>>> \xd0\x94\xd0\xbe\xd0\xbc\xd0\xb0\xd1\x88\xd0\xbd\xd1\x8f\xd1\x8f 
>>> \xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x86\xd0\xb0" />\n>> name="description" 
>>> content="\xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f, 
>>> \xd1\x8f\xd0\xbf\xd0\xbe\xd0\xbd\xd1\x81\xd0\xba\xd0\xb8\xd0\xb5 
>>> \xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8, 
>>> \xd1\x8f\xd0\xbf\xd0\xbe\xd0\xbd\xd1\x81\xd0\xba\xd0\xb8\xd0\xb5 
>>> \xd1\x82\xd0\xb5\xd1\x85\xd0\xbd\xd0\xbe\xd0\xbb\xd0\xbe\xd0\xb3\xd0\xb8\xd0\xb8,
>>>  \xd0\xbd\xd0\xb0\xd1\x83\xd0\xba\xd0\xb0 
>>> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd0\xb8, 
>>> \xd1\x83\xd1\x87\xd0\xb5\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5 
>>> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f, 
>>> \xd0\xba\xd0\xbe\xd0\xbc\xd0\xbf\xd0\xb0\xd0\xbd\xd0\xb8\xd0\xb8 
>>> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f, 
>>> \xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x80\xd1\x8b 
>>> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f" />\n\r\n\r\n'
>>> soup = BeautifulSoup(html)
>>> print soup.prettify()

http://www.w3.org/1999/xhtml";>
 
  
  
   Japanese innovation | Япония инновации
  
  
  
 


best wishes

Ray McBride

On 9 Sep, 10:06, Oleg Oltar  wrote:
> Hi!
>
> One of my tests returned following text ()
>
> The test:
> from django.test.client import Client
>  c = Client()
> resp = c.get("/")
> resp.content
>
> In [25]: resp.content
> Out[25]: '\r\n\r\n\r\n Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>\r\n\r\n xmlns="http://www.w3.org/1999/xhtml";>\r\n  \r\n     http-equiv="content-type" content="text/html; charset=utf-8" />\r\n
> \r\n    \nJapanese innovation |
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f
> \xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8\n\r\n
> \n content="\xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> \xd0\xa2\xd0\xb5\xd1\x85\xd0\xbd\xd0\xbe\xd0\xbb\xd0\xbe\xd0\xb3\xd0\xb8\xd0\xb8,
> \xd0\x98\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8,
> \xd0\x94\xd0\xbe\xd0\xbc\xd0\xb0\xd1\x88\xd0\xbd\xd1\x8f\xd1\x8f
> \xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x86\xd0\xb0" />\n name="description"
> content="\xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> \xd1\x8f\xd0\xbf\xd0\xbe\xd0\xbd\xd1\x81\xd0\xba\xd0\xb8\xd0\xb5
> \xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8,
> \xd1\x8f\xd0\xbf\xd0\xbe\xd0\xbd\xd1\x81\xd0\xba\xd0\xb8\xd0\xb5
> \xd1\x82\xd0\xb5\xd1\x85\xd0\xbd\xd0\xbe\xd0\xbb\xd0\xbe\xd0\xb3\xd0\xb8\xd0\xb8,
> \xd0\xbd\xd0\xb0\xd1\x83\xd0\xba\xd0\xb0
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd0\xb8,
> \xd1\x83\xd1\x87\xd0\xb5\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> \xd0\xba\xd0\xbe\xd0\xbc\xd0\xbf\xd0\xb0\xd0\xbd\xd0\xb8\xd0\xb8
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f,
> \xd1\x82\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x80\xd1\x8b
> \xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f" />\n\r\n\r\n
>
> Is there a way I can convert it to normal readable text? (I need for example
> to find a string of text in this response to check if my test case Pass or
> failed)
--~--~-~--~~~---~--~~
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: apache2+mod_wsgi: 403 Forbidden

2009-09-09 Thread Léon Dignòn

I solved the Problem. It was my fault and because of that the default
virtual host served the request. :(

Thank you for your help!

On 9 Sep., 01:21, Graham Dumpleton  wrote:
> On Sep 9, 12:28 am, Matias  wrote:
>
> > sorry, I messed up!
>
> > I'm not sure now, i couldn't test it, but maybe you should set the Directory
> > directive in the specific path where wsgi files are
>
> > 
> >        Order Allow,Deny
> >        Deny from all
> > 
> > 
>
> Don't use wildcards, ie., '*', like that, it is unnecessary in this
> sort of situation and technically will match other directories you may
> not have intended to expose, if they so happened to exist.
>
> Graham
>
>
>
> >        Order Allow,Deny
> >        Allow from all
> > 
>
> > Regards,
> > Matias.
>
> > On Tue, Sep 8, 2009 at 11:04 AM, Matias  wrote:
> > > You should use Directory with the real path, not the alias
>
> > > 
> > >        Order Allow,Deny
> > >        Deny from all
> > > 
> > > 
> > >        Order Allow,Deny
> > >        Allow from all
> > > 
>
> > > like in the example :)
>
> > > Regards,
> > > Matias.
>
> > > On Mon, Sep 7, 2009 at 5:56 PM, Léon Dignòn  wrote:
>
> > >> No, I have it here, but forgot to post it:
>
> > >> 
> > >>        Order Allow,Deny
> > >>        Deny from all
> > >> 
> > >> 
> > >>        Order Allow,Deny
> > >>        Allow from all
> > >> 
>
> > >> On Sep 7, 10:11 pm, Matias  wrote:
> > >> > I think you missed the allow directive in your apache conf.
>
> > >> > Example from [1]
>
> > >> > Alias /media/ /usr/local/django/mysite/media/
>
> > >> > 
> > >> > Order deny,allow
> > >> > Allow from all
> > >> > 
>
> > >> > WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi
>
> > >> > 
> > >> > Order deny,allow
> > >> > Allow from all
> > >> > 
>
> > >> > [1]http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
>
> > >> > HTH,
> > >> > Matias.
>
> > >> > On Mon, Sep 7, 2009 at 2:55 PM, Léon Dignòn 
> > >> wrote:
>
> > >> > > I get a 403 forbidden.
>
> > >> > > I serve Django with apache2+mod_wsgi. I disabled some plugins I think
> > >> > > I don't need. Set the listen port to 8000 on localhost only. Later I
> > >> > > will serve django through reverse proxy on cherokee webserver. But 
> > >> > > for
> > >> > > now, localhost:8000 is returning a 403 forbidden error.
>
> > >> > > Any ideas?
>
> > >> > > # error.log
> > >> > >    [Mon Sep 07 17:14:59 2009] [error] [client 127.0.0.1] client
> > >> > > denied by server configuration: /htdocs
>
> > >> > > lwp-request -m GET -Sedhttp://127.0.0.1:8000/
> > >> > > lwp-request  -m GET -Sed
> > >> > >http://beispiel.de:8000/
> > >> > >    GEThttp://127.0.0.1:8000/--> 403 Forbidden
> > >> > >    Connection: close
> > >> > >    Date: Mon, 07 Sep 2009 14:56:32 GMT
> > >> > >    Server: Apache
> > >> > >    Content-Length: 202
> > >> > >    Content-Type: text/html; charset=iso-8859-1
> > >> > >    Client-Date: Mon, 07 Sep 2009 14:56:32 GMT
> > >> > >    Client-Peer: 127.0.0.1:8000
> > >> > >    Client-Response-Num: 1
> > >> > >    Title: 403 Forbidden
>
> > >> > > # /etc/apache2/ports.conf
> > >> > >    NameVirtualHost 127.0.0.1:8000
> > >> > >    Listen 127.0.0.1:8000
>
> > >> > > # /etc/apache2/sites-enabled/000-default
> > >> > >    
> > >> > >            ServerName localhost
> > >> > >            ServerAdmin webmas...@localhost
> > >> > >    
>
> > >> > > # /etc/apache2/sites-enabled/beispiel.de
> > >> > >    
> > >> > >            ServerNamewww.beispiel.de
> > >> > >            ServerAlias beispiel.de
> > >> > >            ServerAdmin daniel.nicc...@gmail.com
>
> > >> > >            DocumentRoot /var/www/django/beispiel
>
> > >> > >            Alias /robots.txt  /var/www/django/beispiel/media/
> > >> > > robots.txt
> > >> > >            Alias /favicon.ico /var/www/django/beispiel/media/
> > >> > > favicon.ico
> > >> > >            Alias /media/      /var/www/django/beispiel/media/
>
> > >> > >            ErrorLog  "|/usr/sbin/rotatelogs /var/log/apache2/
> > >> > > beispiel.de/error_log.%Y-%m-%d 86400"
> > >> > >            CustomLog "|/usr/sbin/rotatelogs /var/log/apache2/
> > >> > > beispiel.de/access_log.%Y-%m-%d 86400" common
>
> > >> > >            WSGIScriptAlias / /var/www/django/wsgi-scripts/
> > >> > > beispiel.wsgi
> > >> > >    
>
> > >> > > # mods-enabled
> > >> > >    alias.conf
> > >> > >    alias.load
> > >> > >    auth_digest.load
> > >> > >    authn_file.load
> > >> > >    authz_default.load
> > >> > >    authz_groupfile.load
> > >> > >    authz_host.load
> > >> > >    authz_user.load
> > >> > >    status.conf
> > >> > >    status.load
> > >> > >    wsgi.conf
> > >> > >    wsgi.load
>
> > >> > --
> > >> > :wq- Hide quoted text -
>
> > >> > - Show quoted text -
>
> > > --
> > > :wq
>
> > --
> > :wq- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to 

Re: formatting dates for DateTimeField()

2009-09-09 Thread Daniel Roseman

On Sep 9, 9:21 am, Gonzalo  wrote:
> How would you store that into the database, what type of field on the
> model I mean? should I store the number of seconds + number of days in
> seconds? or the datetime.timedelta() object?
>
> Thanks

You can't store a timedelta object in a database. And annoyingly,
there's no simple method to convert a timedelta to seconds. You have
to do it manually:
time_diff_seconds = time_diff.days * 86400 + time_diff.seconds

So now you have a value in seconds you can store in an IntegerField.
--
DR.
--~--~-~--~~~---~--~~
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: breadcrumb solution

2009-09-09 Thread Mike Dewhirst

Daniel Roseman wrote:
> On Sep 9, 7:32 am, Mike Dewhirst  wrote:
>> I would like to get breadcrumbs working in a simple way. Could anyone
>> please help?
>>
>> I think I need a singleton with a dict like this ...
>>
>> bread = singleton()
>>
>> bread.dct['last_title'] =
>>
>> Within each view and before doing anything else I want to ...
>>
>> def someview(request):
>> title = 'whatever'
>> crumb = bread.dct['last_title']
>> bread.dct['last_title'] = title
>> # put title and crumb into the view context for extraction
>> # in the template as {{title}} and {{crumb}}
>>
>> Is there a better way?
>>
>> Thanks
>>
>> Mike
> 
> Why do you need a singleton here? This is a pattern you don't see
> often in Python, so I'm intrigued as to why you think you need it.
> 
> Anyway, the better way is to do this as a templatetag.

I'm obviously off track. I just looked at template tags again and can't 
see anything - other than making a custom tag which seems a bit much for 
me just at the moment.

Apart from hard-coding variables in a template and passing the values in 
a context dictionary, how should it be done? Can you point me to any 
examples?

Thanks

Mike




> --
> DR.
> > 
> 
> 


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



Encoding question

2009-09-09 Thread Oleg Oltar
Hi!

One of my tests returned following text ()

The test:
from django.test.client import Client
 c = Client()
resp = c.get("/")
resp.content

In [25]: resp.content
Out[25]: '\r\n\r\n\r\nhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>\r\n\r\nhttp://www.w3.org/1999/xhtml";>\r\n  \r\n\r\n
\r\n\nJapanese innovation |
\xd0\xaf\xd0\xbf\xd0\xbe\xd0\xbd\xd0\xb8\xd1\x8f
\xd0\xb8\xd0\xbd\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8\n\r\n
\n\n\n\r\n\r\n

Is there a way I can convert it to normal readable text? (I need for example
to find a string of text in this response to check if my test case Pass or
failed)

--~--~-~--~~~---~--~~
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 initialization of sample data

2009-09-09 Thread Jan Ostrochovsky

Bill,

thanks for answer, my comments are inline:

On Sep 8, 4:29 pm, Bill Freeman  wrote:
> Well, do you want this to happen every time that the module is imported?  Or
> spend time
> each server start determining that these items are already in the data base
> and skipping
> the initialization?  If not, then you're stuck telling the system when to do
> this anyway (perhaps
> a syncdb extension that does them if it has to create the database?).

I meant not every time module is imported, only when doing "syncdb" or
"evolve" (Django Evolution). So no checks if items are in database are
needed, database could be dropped and newly created before this
operation.

> You do realize that having initializers as default arguments, that they
> consume virtual memory
> forever, whether the database is already loaded or not.

This is good remark. Solution how to avoid that could be to have
somewhere (maybe in settings) flag, for example LOAD_SAMPLE_DATA=True/
False, and these data would be loaded only when set. Or running syncdb
or evolve could temporarily set this flag to true.

>  That isn't
> significant for loading 3 rows,
> as in your example, but I presume that you're actually loading a much larger
> set.

Larger, but not much. Approximately 0 - 30 items in various classes/
tables.

> I typically have a CSV file, or a pickle of a list of dictionaries, and use
> csv.DictReader or cpickle.load
> in a loop that creates a model instance, populates such fields as have keys
> in the source, and saves
> the instance.  I think that it's less work than figuring out how to
> configure some extension, and if you
> let it be driven by the keys present, the code is pretty generic (at least
> for the pickle; with the CSB
> you typically want to convert some strings to ints, floats, and bools.  You
> can also use XML, but I find
> it more complicated, though attributes could control conversions.)
>
> I've taken to putting that code in a separate load.py file, so that even the
> code isn't loaded in the
> server.  You could also just hand code a list of dictionaries in such a
> file.  I still wind up running the
> code from the manage shell, though you could certainly create, for example,
> a view that imports the
> load.py only if the view is referenced (by someone with enough privelege),
> and runs the code.  Or
> you could figure out how to attach it to syncdb.
>
> But you should probably look at fixtures.  I haven't, as yet, but should.
> They seem to be a supported
> means of initializing a database.

In my previous projects (not in Django), it was common practise to
load some data in CSV or XML.
Django fixtures - I used them several times, but I see it only as
alternative of CSV or XML.

Disadvantage of these traditional approaches is, that data are
maintained separately from code. When the code evolves (e.g. renaming
attributes, moving attributes between classes or packages, ...), the
same changes need to be done in files with sample data, and it seems
tedious to me.

I know, that I cannot avoid traditional approach, when e.g. migrating
production data from one version of application to another version, it
is unthinkable to put production data in the code ;).

But when developing application (currently my case), there is only
relatively small set of sample testing data, and I see as big avantage
and developer's comfort, to be able modify sample data accordingly
with code modification.

If such functionality would become part of Django, or Django
Evolution, I'd be happy.

Jano

>
> Bill
>
> On Mon, Sep 7, 2009 at 4:43 AM, Jan Ostrochovsky 
> > wrote:
>
> > Thanks Bill, yes, that is one possible solution, when implementing
> > such feature from the scratch.
>
> > I am only asking, if there is some existing framework for such need,
> > which I see as common.
>
> > For example some add-on to Django, which will do this for me. Let's
> > imagine additional option for any field of Django model, e.g.:
>
> > class Person(models.Model):
> >  firstname = models.CharField(max_length=30, initial_values="John,
> > Bill, Peter")
> >  lastname = models.CharField(max_length=70, initial_values="Smith,
> > Clinton, Parker")
> >  ...
>
> > Django with such add-on could be able to build initial database from
> > these values, for example when running syncdb or other way.
>
> > Am I more readable now?
>
> > Jano
>
> > On Aug 20, 10:09 pm, Bill Freeman  wrote:
> > > Perhaps I'm not understanding correctly, but how about, assuming you have
> > a
> > > function
> > > run_data_inits() that calls your chain of init_sample_data() functions:
>
> > > $ python manage.py shell
>
> > > >>> import myproject.myapp.models as m
> > > >>> m.run_data_inits()
> > > >>> ^D
>
> > > Bill
>
> > > On Thu, Aug 20, 2009 at 9:25 AM, Jan Ostrochovsky <
>
> > > jan.ostrochov...@gmail.com> wrote:
>
> > > > Hello,
>
> > > > we are in the initial phase of software project, and data model and
> > > > names of attributes are changing very often, and very often we need to
>

Re: breadcrumb solution

2009-09-09 Thread Daniel Roseman

On Sep 9, 7:32 am, Mike Dewhirst  wrote:
> I would like to get breadcrumbs working in a simple way. Could anyone
> please help?
>
> I think I need a singleton with a dict like this ...
>
> bread = singleton()
>
> bread.dct['last_title'] =
>
> Within each view and before doing anything else I want to ...
>
> def someview(request):
>     title = 'whatever'
>     crumb = bread.dct['last_title']
>     bread.dct['last_title'] = title
>     # put title and crumb into the view context for extraction
>     # in the template as {{title}} and {{crumb}}
>
> Is there a better way?
>
> Thanks
>
> Mike

Why do you need a singleton here? This is a pattern you don't see
often in Python, so I'm intrigued as to why you think you need it.

Anyway, the better way is to do this as a templatetag.
--
DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Incorrect {{root_path}} in classes derived from AdminSite

2009-09-09 Thread Vlastimil Zima

Hello,
I found out, that if I made derived class of
django.contrib.admin.sites.AdminSite admin generated by this AdminSite
in unable to to create correct links e.g. for Logout (http://
127.0.0.1:8000/admin/Nonelogout/), Change Password (http://
127.0.0.1:8000/admin/Nonepassword_change/), etc. (examples are from
index page). I am not sure whether it is mistake at my site or
somewhere else.

Everything I changed since createproject and syncdb:

- add 'django.contrib.admin' to INSTALLED_APPS
- create sites.py :

from django.contrib.admin.sites import AdminSite

class TestAdminSite(AdminSite):
   def get_urls(self):
   """
   So far call super.get_urls, prepared for extensions
   """
   urlpatterns = []
   urlpatterns.extend( super(TestAdminSite, self).get_urls() )
   return urlpatterns
 def urls(self):
   return self.get_urls()
   urls = property(urls)

admin_site = TestAdminSite()

- generate admin in urls.py :

from django.conf.urls.defaults import *
from sites import admin_site
urlpatterns = patterns('',
   (r'^admin/', include(admin_site.urls)),
)

Although there are no registered models, it can be observed that links
are not correct.

Any idea how to solve this problem or confirm that it is a bug will be
helpful.

--~--~-~--~~~---~--~~
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 define variables.

2009-09-09 Thread fchow

The template wants a dictionary of key-value pairs, and you called
that dict 'variables' in your code.
So you need to define a variable called variables that holds the data
to pass to the template. Example:
variables = {'foo':'bar', 'a':3}
return render_to_response('survey.html', variables)


Now your template can print the value of foo and a using {{ foo }} and
{{ a }}



On Sep 8, 9:26 pm, putih  wrote:
> then how to define the variables..??
>
> On Sep 8, 11:35 pm, Kenneth Gonsalves  wrote:
>
> > On Wednesday 09 Sep 2009 7:50:36 am putih wrote:
>
> > > here is my code :-
> > > @login_required
> > > def survey(request):
> > >   return render_to_response('survey.html', variables)
>
> > > please help me because this is my first time using django..
> > > really need your help guys..
>
> > you have not defined your variables.
> > --
> > regards
> > kghttp://lawgon.livejournal.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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



changing model manager

2009-09-09 Thread goobee

hi there
django's features for handling data from a database are great.
Unfortunately I work with a legacy database which does not quite fit
into djangos requirements:

Class Member(models.Model)
mnum = models.ForeignKey(, primary_key=True)
enum = models.ForeignKey(, primary_key=True)
.

--> no single id_...  as PK


Would it be a big deal to change django to be able to handle these
database models?
if no, any hints where to find the 'switch' ;-)

thanks
goobee
--~--~-~--~~~---~--~~
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: Security: Django vs popular PHP apps?

2009-09-09 Thread Nick Lo

> I am hoping to get some reasonably knowledgeable, and unbiased,
> responses.
>
> I was thinking about putting together a wordpress blog. Then I came
> across a recent slashdot article about recent wordpress security
> issues. I did a little research, and found that wordpress has quite a
> history of security issues. A lot of people argue that wordpress has
> serious design flaws when it comes to such issues.
>
> I also understand that joomla, and even drupal, have a history of
> security issues.
>
> Certainly django has less issues, but then, let's be honest, there are
> a lot less django sites. Hackers love to target the more popular
> apps.
>
> Then again, I have heard some fairly knowledgeable people claim that
> django is designed with security in mind. Although I am not a PHP
> hater, I have found that python developers tend to be less hackish,
> and more design oriented.
>
> I would love to get a response from somebody who actually knows a
> little about php, and the popular php apps, as well as some django.

My background: I moved to using mostly Django/Python last year after  
using PHP for 9'ish years. Included in that has been developing some  
sites with Wordpress. Even more relevant I also spent this last Sunday  
hurriedly upgrading various Wordpress blogs, some for clients, some  
for clients of clients. I've seen several of these sites hacked  
previously.

You don't say who or what the blog is for. If it's for personal and  
frequent use then you only have to look at how many active django  
developers themselves use Wordpress. I say frequent as it's easier to  
be reminded of security upgrades. If it's for someone else factor in  
having to upgrade it for them. Also factor in upgrading the various  
plugins you'll find you end up using. Some of those plugins may break  
during a WP upgrade. You also don't really mention your own knowledge.  
Remember to subscribe to the Wordpress development blog feed to keep  
up to date with upgrades.

I've now stopped doing any client sites using it and want to move our  
blogs away from it. The security issues are one reason but I'd not say  
Wordpress is necessarily the most insecure app, as you say it's quite  
likely it is being targetted as much due to its ubiquity. Besides, you  
could argue that its fairly frequent attacks will make the developers  
more vigilant than many other projects.

Having said that there are things about it's structure that I didn't  
like (aside from the code): It stores all app content in the public  
folder (django does not advise this in contrast). It includes content  
(eg image uploads) inside what is partly an application folder (wp- 
content) which means not only are there folders inside an app that  
need to be writable for uploaded content but also that manual upgrades  
are a fiddle. Third party plugins exist in this directory too and I've  
had several require additional directories with full write access.  
Many of its options are stored as serialized data and are written by  
any new plugins making spotting unwelcome hacked entries more  
difficult (I've had to do this).

Another reason is simply development. Wordpress has loads of plugins  
but if you're any kind of fussy developer there will always be things  
you want to change. As soon as you change them they no longer fit into  
the upgrade cycle and you're then maintaining code like you would any  
other project without the lazy convenience of Wordpress.

As far as comparing Django to Wordpress; the comparison is flawed. As  
others will point out, django is a framework better compared to, for  
PHP, Zend Framework, Symfony, CakePHP, etc. You'd then have to build  
your own or find one of the many blog and bloggish apps developed on  
Django.

As far as python developers being less hackish I do wonder in part if  
that has to do with the somewhat higher barrier to entry particularly  
for web apps. PHP: http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: multi-table inheritance - how to access child object methods/attributes

2009-09-09 Thread Jan Ostrochovsky

Manfre, thanks.

It seems like ultimate solution, on the other hand, it seems quite low
level and adds more complexity, which should be added not only for
__unicode__() but also for each method or attribute, which I'd handle
this way.

I meant, if here is something like that:

document_object.some_method_name()
document_object.some_attribute

when such method or attribute does not exist for Document object, it
will look in the child class[es recursively].

Jano

On Sep 8, 5:14 pm, Manfre  wrote:
> This digs through _meta to figure any related fields and tries each
> until one works.
>
> class Document(models.Model):
>     ...
>
>     def __unicode__(self):
>         name_map = self._meta._name_map
>
>         subs = [x for x in name_map if isinstance(name_map[x][0],
> RelatedObject)]
>
>         for field in subs:
>             try:
>                 sub = getattr(self, field, None)
>                 return sub.__unicode__()
>             except ObjectDoesNotExist:
>                 pass
>
>         return u'Document {0}'.format(self.id)
>
> On Sep 8, 9:01 am, Jan Ostrochovsky 
> wrote:
>
> > Ugly workaround:
>
> > class Document(models.Model):
> >         pass
> >         def __unicode__(self):
> >                 if self.accountingdocument:
> >                         return self.accountingdocument.__unicode__()
> >                 else:
> >                         return self.__class__.__name_ + ' ' + self.id_
>
> > But I'd prefer solution, where Document class does not know about its
> > child classes (AccountingDocument, etc.). Any idea?
>
> > On Sep 8, 8:31 am, Jan Ostrochovsky 
> > wrote:
>
> > > Hello,
>
> > > class Document(models.Model):
> > >   ...
>
> > > class AccountingDocument(Document):
> > >   ...
>
> > > How am I able to access methods an attributes of some
> > > AccountingDocument instance (e.g. its __unicode__()) from Document
> > > instance? How am I able to retrieve child object from its parent?
>
> > > I tried to search on the web, but I am not a lot wiser after that...
>
> > > Thanks in advance.
>
> > > Jano
--~--~-~--~~~---~--~~
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: formatting dates for DateTimeField()

2009-09-09 Thread Gonzalo

How would you store that into the database, what type of field on the
model I mean? should I store the number of seconds + number of days in
seconds? or the datetime.timedelta() object?

Thanks

> Stop calling int on the return value
>
> >>> import datetime
> >>> time_start = datetime.datetime.now()
> >>> time_end = datetime.datetime.now()
> >>> time_diff = time_end - time_start
> >>> time_diff
>
> datetime.timedelta(0, 9, 126708)>>> print time_diff
>
> 0:00:09.126708
>
--~--~-~--~~~---~--~~
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 display and update selected fields from a model

2009-09-09 Thread Daniel Roseman

On Sep 9, 7:10 am, Jim Myers  wrote:
> I have a database model with many fields, some of which I don't want
> displayed in a form and others I don't want to be editable.  Is it
> possible to do this with a ModelForm?  Or is it even possible with
> regular forms?
>
> Furthermore, I only want the SQL update statement to update ONLY the
> fields actually displayed in the form (only the editable ones).  I
> know it can do it if I write my own SQL but does Django provide a way?
>
> I've read most of the available docs and a lot of stuff on Google and
> still don't see how to do these things.
>
> Any help/insight will be appreciated!

If you want fields not to display on a form, use the exclude attribute
when defining the modelform - see
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form

There isn't a built-in way to have fields display but not be editable,
but you could easily use one of the read-only widgets available on
djangosnippets.org, or simply display them individually in your
template.

As regards updating, Django will only update the fields that have
changed in any case.
--
DR.
--~--~-~--~~~---~--~~
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: Editors of choice

2009-09-09 Thread Benjamin Buch


I second that.

>
> Vim
>


--~--~-~--~~~---~--~~
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: python manage.py syncdb problem

2009-09-09 Thread Zico
On Wed, Sep 9, 2009 at 11:40 AM, ankit rai  wrote:

> hello,
>
> this error shows that there is some postgres db connection exception.please
> check ur connection


As far as i know, everything is ok so far. But, if i check with *python
manage.py dbshell, it can connect!*

-- 
Best,
Zico

--~--~-~--~~~---~--~~
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: unicode error when adding a related object in admin inline

2009-09-09 Thread Miklós

Thanks, Karen. I was using gettext, and replacing it to ugettext
indeed fixed the problem.

On Sep 7, 7:06 pm, Karen Tracey  wrote:
> On Mon, Sep 7, 2009 at 12:53 PM, Miklos  wrote:
>
> > Hi,
>
> > I have models with verbose names translated into Hungarian. The
> > verbose names contain non-ascii characters. I have trouble adding,
> > editing, or deleting related objects through an admin inline. The
> > error I get is below. I can add, edit, delete them perfectly fine
> > directly through their own admin.
>
> > Has anyone seen this before? Is this a bug of admininline or am I
> > doing the something wrong?
>
> > Thanks,
>
> > Miklos
>
> > models.py
> > ---
> > class Topic(models.Model):
>
> >class Meta:
> >verbose_name = _('topic')
>
> What is _ here?  If it's ugettext I don't think you will have a problem.  If
> it's gettext (but why?), there is a bug in admin in this area, see:
>
> http://code.djangoproject.com/ticket/11710
>
> A simple workaround until it is fixed in Django is to always use unicode
> strings, not byte strings, for your verbose_name values.
>
> Karen
--~--~-~--~~~---~--~~
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 deploy an app that gets used by people in multiple time zones

2009-09-09 Thread Margie

Sorry for the delay in response - was on vacation for a few days.

After reading up more on naive and aware timezones in python, this all
makes more sense now.  Thanks for your pointers, they were helpful.

Margie

On Sep 4, 9:03 am, Brian Neal  wrote:
> On Sep 4, 10:47 am, Margie  wrote:
>
>
>
> > Can someone clarify what format dates and times are stored in when
> > using just a standard DateTimeField?  Is mytimezoneencoded in the
> > database or is some generic, non-timezone-specific date/time stored?
>
> There is notimezoneencoded. The dates/times are said to be "naive".
>
> It is up to you to assign meaning to the time and to convert to the
> appropriatetimezonefor your users.
>
> You should probably review this:
>
> http://docs.python.org/library/datetime.html
>
> Regards,
> BN
>
> PS. The pytz library is useful for performing conversions between
> timezones.http://pytz.sourceforge.net/
--~--~-~--~~~---~--~~
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 deploy an app that gets used by people in multiple time zones

2009-09-09 Thread Margie

Tracy,

Sorry for the delay, just got back from a short vacation.  Thanks very
much for your clarification.  I think I now understand how to proceed!

On Sep 7, 8:06 pm, Tracy Reed  wrote:
> On Thu, Sep 03, 2009 at 03:48:14PM -0700, Margie spake thusly:
>
> > What is the default when using a django DateTimeField? Does it not
> > save it in UTC? If it is not saving it in UTC, what is it saving it
> > in?
>
> Python has two kinds of DateTime objects: naive and
> non-naive. Non-naive has timezone information with it. But the Django
> DateTimeField can only handle naive DateTime objects since MySQL
> cannot store time zones. So anytime you assign a time to a
> DateTimeField you have to convert it to a standard timezone and UTC is
> the most logical choice.
>
> > I thought that one of the things the DateTimeField did for you
> > was convert your input (whether form a user typed input or from a
> > server call to datetime.datetime.now ()) into some sort of internal
> > representation (UTC?).
>
> I think it would be nice if it did this automatically since that is
> the only thing that makes sense but it does not. Maybe someone out
> there is able to be 100% sure that their data will always be the same
> timezone so they don't want to inconvenience them by forcing
> everything to UTC so they have to do a conversion to localtime when
> they get their data back out. But I think such cases are exceedingly
> rare. So we are all stuck converting to UTC before doing a .save() on
> our models.
>
> > I thought that when I was using the date filter, that it was simply
> > converting that internal representation into my specificied text
> > format.  Am I confused here?
>
> It does that but it does not do any timezone conversions.
>
> > I thought about putting the timezone in the profile but that does have
> > the disadvantage that if the user travels, they would have to update
> > their profile to get dates displayed in whatever location they are
> > at.  I really don't like that since the people that will be using my
> > app are management, and they often travel (and probably won't want to
> > modify their profile all the time).
>
> There is no way around this afaik. They need to learn to do timezone
> conversions in their head or set a timezone in their profile. I label
> the timezone displayed prominently so they know to make the adjustment
> or change their profile.
>
> --
> Tracy Reedhttp://tracyreed.org
>
>  application_pgp-signature_part
> < 1KViewDownload
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---