Connecting to a database

2011-04-23 Thread Hurin
Hi,

I have a python script where I have to fill the following info to
connect to my DB:

DATABASES = {
'default': {
'ENGINE': 'sqlite3','mysql', # Add 'postgresql_psycopg2',
'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.path.dirname(os.path.abspath( __file__ )) + '/
database/local.db', # Or path to database file if using sqlite3.
'USER': '',  # Not used with sqlite3.
'PASSWORD': '',  # Not used with sqlite3.
'HOST': '',  # Set to empty string for
localhost. Not used with sqlite3.
'PORT': '',  # Set to empty string for
default. Not used with sqlite3.
},


I am not familiar with python, I know that os.path.dirname is a way to
reference the location where the script is being run, but I am not
sure if it is the right syntax to point to my database. Should I leave
it like that or would it be something like

mysql://localhost:3306/dbName"

For reference, I am trying to install CDR-Stats and I have python-
django and python-mysqldb installed.

Thanks to whoever can point me out in the right direction

-- 
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: Ajax headers not work in all browsers?

2011-04-23 Thread Masklinn
On 24 avr. 2011, at 04:38, Daniel França  wrote:
> Hi all,
> I was using JQuery to retrieve some data using AJAX and Django... 
> at my django view code I wrote a verification to check if it's an ajax 
> request:
> if request.is_ajax():
>#Ajax handler
> else:
>   #Not Ajax handler
> 
> and do the properly handler, and here's my Jquery script:
> $('#id_show_updates').load("/profiles/get_updates/"+ 
> document.getElementById('last_update').innerHTML);
> 
> It's working like a charm in Chrome and Opera... but at Firefox django thinks 
> it's not Ajax and  =/ Anyone know someway to solve that?
> 
> Best Regards,
> Daniel França
Would you per chance have some kind of redirection (any redirection) per chance?

Firefox will not forward any explicitly set header (including Ajax ones) across 
redirections. 

-- 
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 ORM question about lookups that span relationships

2011-04-23 Thread Alexander Schepanovski
> Yes, but while raw() has its uses, it's an interesting question: Is
> there a way to do this with the Django ORM or not? It's always hard to
> write raw queries in a database independent way, so there are good cases
> where you want to avoid raw().

You can, with a subrequest:
Blog.objects.filter(pk__in=Entry.objects.filter(pub_date__lte=date(2011,
4, 1), headline__contains='Lennon').values('blog').distinct())

-- 
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 form field

2011-04-23 Thread Karen Tracey
On Wed, Apr 20, 2011 at 11:06 AM, Daniel Gagnon wrote:

> The first one uses a jquery plugin that's discontinued and the second one
> works only in the admin.
>
>
There is also:

https://bitbucket.org/mlavin/django-selectable

Karen
-- 
http://tracey.org/kmt/

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



Ajax headers not work in all browsers?

2011-04-23 Thread Daniel França
Hi all,
I was using JQuery to retrieve some data using AJAX and Django...
at my django view code I wrote a verification to check if it's an ajax
request:
*if request.is_ajax():*
*   #Ajax handler*
*else:*
*  #Not Ajax handler*

and do the properly handler, and here's my Jquery script:
$('#id_show_updates').load("/profiles/get_updates/"+
document.getElementById('last_update').innerHTML);

It's working like a charm in Chrome and Opera... but at Firefox django
thinks it's not Ajax and  =/ Anyone know someway to solve that?

Best Regards,
Daniel França

-- 
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 register EmployeeAdmin using atributes in Person class

2011-04-23 Thread Guevara
I got put in the form of employee the form of Houses using
StackedInline:


class HouseInline(admin.StackedInline):
model = House
max_num = 1

class EmployeeAdmin(admin.ModelAdmin):
search_fields = ['person__name','person__cpf']
list_display = ("name","cpf","date_born","date_inclusion")
ordering = ["-name"]
list_filter = ("date_inclusion",)
list_per_page = 10
inlines = [HouseInline]

admin.site.register(Employee, EmployeeAdmin)

Now I need collapse the forms of Houses in edit form of Employee, if I
register mora than 2 houses, I have two forms of Houses in edit form
employee. =/
And the address combobox still showing all address register in
database, i need show olnly adress of employee or adress of the house.

Thanks.




On 23 abr, 12:46, Guevara  wrote:
> Thank you Ramiro!
>
> Now i have the atributes Person in form Employee. =)
>
> I added the attribute address and house in Employee class:
>
> models.py
>
> class Employee(Person):
>     person = models.OneToOneField(Person, parent_link=True)
>     # Relationship OneToOne with Address
>     address = models.OneToOneField(Address)
>     # Relationship with Houses
>     house = models.ForeignKey(Houses)
>
>     def __unicode__(self):
>         if self.person:
>             return "%s %s (%s)" % (self.name, self.tel, self.address)
>         else:
>             return "%s (%s)" % (self.name, self.address)
>
> admin.py
>
> from django.contrib import admin
> from imobiliaria.employee.models import Employee
> admin.site.register(Employee)
>
> But when registering a new Employee, the form show in the combobox
> others addresses and other houses of other entries, you know how I can
> fix?
>
> Thanks!!
>
> On 23 abr, 00:22, Ramiro Morales  wrote:
>
>
>
>
>
>
>
> > On Fri, Apr 22, 2011 at 11:55 PM, Guevara  wrote:
> > > [...]
>
> > > class Person(models.Model):
> > >    name = models.CharField(max_length=50)
> > >    date_inclusion = models.DateField()
>
> > > class Employee(models.Model):
> > >    person = models.OneToOneField(Pessoa)
>
> > > I reed this dochttp://docs.djangoproject.com/en/dev/ref/contrib/admin/
> > > but could not find this information.
>
> > Try with
>
> > class Employee(Person):
> >     person = models.OneToOneField(Person, parent_link=True)
>
> > or simply with
>
> > class Employee(Person):
> >     pass
>
> > It you don't want/need control of the name of the 1to1 relationship
> > between Employee and Person.
>
> > Also, see
>
> >http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield..
>
> > --
> > Ramiro Morales

-- 
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: Problems with running Hello world app, urls.py probably ignored

2011-04-23 Thread Rafael Durán Castañeda
I'm not sure, I'm quite new in django, but I think you need to include 
dashboard in INSTALLED_APPS and looking your urls.py in order to see 
hello view you need to type http://127.0.0.1:8000/john/hello


On 23/04/11 21:57, Honza Javorek wrote:

Hello guys,

I have searched to solve this for a whole evening without any results.
I have read all known "my first app in django" tutorials, but my test
app just isn't working.

I have project called "john". In it's directory I have app package
"dashboard" containing init, models, tests and views. Moreover, in
project directory "john" are init, manage, settings and urls files. My
urls.py:

from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('john',
 (r'^$', 'dashboard.views.hello'),
 (r'^hello/$', 'dashboard.views.hello'),
)

My dashboard/views.py:

from datetime import datetime
from django.http import HttpResponse
def hello(request):
 return HttpResponse(datetime.now().strftime('%H:%M:%S'))

My settings.py (not complete, I copied only apparently important
parts):

ROOT_URLCONF = 'emil.urls'
INSTALLED_APPS = (
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
)

Now what is the problem. If I go to my "john" directory and I launch
server, it looks like this:

.../john$ python manage.py runserver
Validating models...
0 errors found
Django version 1.3, using settings 'john.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[23/Apr/2011 14:40:31] "GET / HTTP/1.1" 200 2047
[23/Apr/2011 14:40:38] "GET / HTTP/1.1" 200 2047

but if I go to the browser and I type http://127.0.0.1:8000/ or
http://127.0.0.1:8000/hello, it shows me Django welcome screen (It
worked! ... you haven't configured any URLs.). According to it's text
I assume it completely ignores what I have configured in urls.py. I
can't get over this screen, I haven't seen any 404 yet or anything
else. Welcome screen is the most far place I managed to get in half of
a day spent with Django :(

Thanks for any help,

Honza Javorek



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



Problems with running Hello world app, urls.py probably ignored

2011-04-23 Thread Honza Javorek
Hello guys,

I have searched to solve this for a whole evening without any results.
I have read all known "my first app in django" tutorials, but my test
app just isn't working.

I have project called "john". In it's directory I have app package
"dashboard" containing init, models, tests and views. Moreover, in
project directory "john" are init, manage, settings and urls files. My
urls.py:

from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('john',
(r'^$', 'dashboard.views.hello'),
(r'^hello/$', 'dashboard.views.hello'),
)

My dashboard/views.py:

from datetime import datetime
from django.http import HttpResponse
def hello(request):
return HttpResponse(datetime.now().strftime('%H:%M:%S'))

My settings.py (not complete, I copied only apparently important
parts):

ROOT_URLCONF = 'emil.urls'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
)

Now what is the problem. If I go to my "john" directory and I launch
server, it looks like this:

.../john$ python manage.py runserver
Validating models...
0 errors found
Django version 1.3, using settings 'john.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[23/Apr/2011 14:40:31] "GET / HTTP/1.1" 200 2047
[23/Apr/2011 14:40:38] "GET / HTTP/1.1" 200 2047

but if I go to the browser and I type http://127.0.0.1:8000/ or
http://127.0.0.1:8000/hello, it shows me Django welcome screen (It
worked! ... you haven't configured any URLs.). According to it's text
I assume it completely ignores what I have configured in urls.py. I
can't get over this screen, I haven't seen any 404 yet or anything
else. Welcome screen is the most far place I managed to get in half of
a day spent with Django :(

Thanks for any help,

Honza Javorek

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



Admin bug w/ deleting a TabularInline'd object?

2011-04-23 Thread Jeff Blaine
I'd like to vet this through the users here before submitting a bug report.

Per the tutorial, all of my models have a defined __unicode__(self) which 
returns a string.

The code is below, but here's the scenario:

1.  I add a 'Device' with associated 'Interface'.

2.  I edit the 'Device', with the inline 'Interface', add another 
'Interface', and save.

3.  I edit the 'Device', with the inline 'Interfaces', select the checkbox 
to delete the interface
I just added, and click save, which results in the interface actually being 
deleted, but
the following error:

...
File "/hostdb/lib/python2.7/site-packages/django/utils/encoding.py" in 
force_unicode
  71. s = unicode(s)

Exception Type: TypeError at /admin/hostdb/device/MM8/
Exception Value: coercing to Unicode: need string or buffer, NoneType found

The POST data shows:

...
interface_set-1-primary  u'on'
interface_set-1-hostname u'foo.our.org'
interface_set-1-ip_address   u'10.1.1.4'
interface_set-1-mac_address  u'somestring'
interface_set-1-device   u'MM8'
...
interface_set-0-DELETE   u'on'
interface_set-0-ip_address   u'10.1.1.1'
interface_set-0-hostname u'test.our.org'
interface_set-0-device   u'MM8'
interface_set-0-mac_address  u''

#--
# myapp/models.py
#--
class Interface(models.Model):
hostname= models.CharField('Hostname',
   primary_key=True,
   max_length=80)

ip_address  = models.IPAddressField('IP Address',
unique=True)

mac_address = models.CharField('MAC Address',
   max_length=40,
   blank=True)

primary = models.BooleanField('Primary',
  default=False)

# the following on_delete may not be the right thing to do
device  = models.ForeignKey('Device',
null=True,
blank=True,
verbose_name='Associated device',
on_delete=models.DO_NOTHING)

def __unicode__(self):
return self.hostname

class Device(models.Model):

propertyno  = models.CharField('Property Number',
   max_length=10,
   primary_key=True)

def primary_hostname(self):
for i in self.interface_set.all():
if i.primary:
return i.hostname
return 'UNKNOWN'

def __unicode__(self):
h = self.primary_hostname()
if h == 'UNKNOWN':
return self.propertyno
return h

#--
# myapp/admin.py
#--
from hostdb.models import Device, Interface

class InterfaceInline(admin.TabularInline):
model = Interface
extra = 0

class DeviceAdmin(admin.ModelAdmin):
inlines = [InterfaceInline]

admin.site.register(Device, DeviceAdmin)
admin.site.register(Interface)

-- 
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: Best-practice for building URLs in templates with JavaScript

2011-04-23 Thread akaariai
On Apr 23, 6:43 pm, Shawn Milochik  wrote:
> It occurs to me now that I could just use a placeholder, and replace
> that in JavaScript:
>     Update Payment
>
> Then use the JavaScript to replace the string 'payment_id' (or a regex
> on its location in the URL) when the user takes action. It also moves
> all of the logic out of views and urls, which I think is probably
> best.

This is exactly what I have been doing. It is bit of a hack, but works
very well in practice.

 - Anssi

-- 
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: bound form with ModelChoiceField

2011-04-23 Thread Andy McKay
> what is the best way of do what I want to do?
> I don't think it will be store firstForm.data o request.POST in
> session it's a good idea, so, what are the other possibilities?

I would recommend taking a copy of the clean data, then run through and just 
change your ModelChoiceField back into the object ids.

new_dict = form.cleaned_data.copy()
new_dict['option'] = new_dict['option'].pk

Might work. You should then be able to cleanly store that in a session and 
repopulate forms with it again later.
--
  Andy McKay
  a...@clearwind.ca
  twitter: @andymckay
 

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



Re: django 1.1 performance versus django 1.2 performance

2011-04-23 Thread akaariai


On Apr 23, 11:54 am, Torsten Bronger 
wrote:
> Does anybody have estimates or figures concerning the impact of
> middleware?  I love the middleware framework and I make extensive
> use of it but sometimes I'm afraid it slows down every request
> significantly, especially if you have a project with cheap view
> functions.
>
> And then, the number of "canonical" middleware has increased between
> Django versions as far as I can see.

The performance impact of a middleware depends almost completely on
what a given middleware does. If I am not mistaken adding a middleware
that does nothing gives you just one function call per the
middleware's functions (process_request, process_view, ...) when
processing a request. If you do not have insane amounts of middlewares
defined then there should be no performance problems.

However, if you do something complex in the middleware then
performance will of course be affected.

In general I have a feeling that Django is still fast enough, and the
added features outweigh the performance penalty.

 - Anssi

-- 
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: cx_Oracle error: ImproperlyConfigured

2011-04-23 Thread kamal sharma
No it was .profile of mine. Now I have set the LD_LIBRARY_PATH in app.wsgi
as mentioned below and when I print the os.environ in the beginning of
views.py then it shows that newly added value.

os.environ["LD_LIBRARY_PATH"] = "/opt/app/oracle/products/11.2.0/lib"

Is there any problem in this statement for connecting the database? The
error show in this line only. I tried all the 3 way, but nothing is working.

connection = cx_Oracle.Connection("%s/%s@%s" % ('foo', 'baar', 'db'))
connection = cx_Oracle.connect("foo/baar@db")
connection = cx_Oracle.connect('foo/baar@db')


But Still the issue is not resolved.

Thanks,

On Sat, Apr 23, 2011 at 2:42 AM, Jirka Vejrazka wrote:

> .profile of which user? Yours or the one running webserver? Have you
> confirmed that these are set (e.g. by writing those to a file at the
> beginning of your views.py)?
>
>  Cheers
>
>Jirka
>
> On 22/04/2011, kamal sharma  wrote:
> > Yes, i am getting this error when i used from the web application. Also
> all
> > the
> > user have the permission to webserver to read all Oracle client files.
> >
> > Not sure how it got set to LD_LIBRARY_PATH
> > /opt/apache-2.2.16/lib:/usr/local/lib:
> >
> > I have defined the LD_LIBRARY_PATH and ORACLE_HOME as follows in .profile
> >
> > export ORACLE_HOME=/opt/app/oracle/products/11.2.0
> > export LD_LIBRARY_PATH=/opt/app/oracle/products/11.2.0/lib
> >
> > Also tried it in .cshrc file also. But nothing is working.
> >
> > setenv ORACLE_HOME "/opt/app/oracle/products/11.2.0"
> > setenv LD_LIBRARY_PATH "$ORACLE_HOME/lib32:$ORACLE_HOME/lib"
> > setenv LD_LIBRARY_PATH /usr/X11R6/lib:/usr/local/lib
> >
> >
> > I have written a sample script and it works, when i run from the command
> > prompt.
> >
> > filename: test_db.py
> > import cx_Oracle
> > from pprint import pprint
> >
> > connection = cx_Oracle.Connection("%s/%s@%s" % ('foo', 'bar', 'db'))
> > cursor = cx_Oracle.Cursor(connection)
> > sql = "SELECT name FROM prs where rownum < 10"
> > cursor.execute(sql)
> > data = cursor.fetchall()
> > pprint(data)
> > cursor.close()
> > connection.close()
> >
> > Getting proper output:
> >
> > [me] ~/install_cx_oracle> /usr/local/bin/python test_db.py
> > [('Robert Craig',),
> >  ('Darren Kerr',),
> >  ('Aviva Garrett',),
> >  ('Pasvorn Boonmark',),
> >  ('Dave Wittbrodt',),
> >  ('Pasvorn Boonmark',),
> >  ('Rajkumaran Chandrasekaran',),
> >  ('Pasvorn Boonmark',),
> >  ('Pasvorn Boonmark',)]
> >
> >  But samething when i write in django views.py then getting exception.
> >
> >
> > Request Method: GET
> > Request URL: https://server/web/test/cases
> > Django Version: 1.2.1
> > Exception Type: DatabaseError
> > Exception Value: Error while trying to retrieve text for error ORA-01804
> > Exception Location: /web/views.py in cases, line 43
> > Python Executable: /bin/python
> > Python Version: 2.6.6
> >
> > Thanks,
> >
> >
> >
> > On Thu, Apr 21, 2011 at 3:37 PM, kamalp.sha...@gmail.com <
> > kamalp.sha...@gmail.com> wrote:
> >
> >> Hi,
> >>
> >> I have installed cx_Oracle module in one of my Solaris box and then
> >> trying to create a django page to read data from oracle db. But I am
> >> getting following errors.
> >>
> >>
> >> mod_wsgi (pid=2600): Exception occurred processing WSGI script '/opt/
> >> www/ui/foo/web/app.wsgi'.
> >> Traceback (most recent call last):
> >> File "/opt/www/ui/foo/web/app.wsgi", line 30, in application
> >> return _application(environ, start_response)
> >> File "/usr/local/packages/python/2.6.6/lib/python2.6/site-packages/
> >> django/core/handlers/wsgi.py", line 230, in __call__
> >> self.load_middleware()
> >> File "/usr/local/packages/python/2.6.6/lib/python2.6/site-packages/
> >> django/core/handlers/base.py", line 42, in load_middleware
> >> raise exceptions.ImproperlyConfigured('Error importing middleware %s:
> >> "%s"' % (mw_module, e))
> >> ImproperlyConfigured: Error importing middleware web.web.framework:
> >> "ld.so.1: httpd: fatal: libclntsh.so.11.1: open failed: No such file
> >> or directory"
> >>
> >>
> >> I have tried from python shell and i can able to import cx_Oracle
> >> module as follows:
> >>
> >> bash-3.00$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
> >> bash-3.00$ python
> >> Python 2.4.4 (#1, Jan 10 2007, 01:25:01) [C] on sunos5
> >> Type "help", "copyright", "credits" or "license" for more information.
> >> >>> import cx_Oracle
> >> >>>
> >>
> >> But from the web I am getting the ImproperlyConfigured: configured
> >> error. Can someone please help me to resolve this issue.
> >>
> >> FYI,
> >>
> >> I have followed this link to install cx_oracle module.
> >>
> >>
> http://agiletesting.blogspot.com/2005/05/installing-and-using-cxoracle-on-unix.html
> >>
> >> Please let me know if you need more info.
> >>
> >> Thanks,
> >> Kamal
> >>
> >> --
> >> 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 un

Re: How to register EmployeeAdmin using atributes in Person class

2011-04-23 Thread Guevara
Thank you Ramiro!

Now i have the atributes Person in form Employee. =)

I added the attribute address and house in Employee class:

models.py

class Employee(Person):
person = models.OneToOneField(Person, parent_link=True)
# Relationship OneToOne with Address
address = models.OneToOneField(Address)
# Relationship with Houses
house = models.ForeignKey(Houses)

def __unicode__(self):
if self.person:
return "%s %s (%s)" % (self.name, self.tel, self.address)
else:
return "%s (%s)" % (self.name, self.address)

admin.py

from django.contrib import admin
from imobiliaria.employee.models import Employee
admin.site.register(Employee)

But when registering a new Employee, the form show in the combobox
others addresses and other houses of other entries, you know how I can
fix?

Thanks!!


On 23 abr, 00:22, Ramiro Morales  wrote:
> On Fri, Apr 22, 2011 at 11:55 PM, Guevara  wrote:
> > [...]
>
> > class Person(models.Model):
> >    name = models.CharField(max_length=50)
> >    date_inclusion = models.DateField()
>
> > class Employee(models.Model):
> >    person = models.OneToOneField(Pessoa)
>
> > I reed this dochttp://docs.djangoproject.com/en/dev/ref/contrib/admin/
> > but could not find this information.
>
> Try with
>
> class Employee(Person):
>     person = models.OneToOneField(Person, parent_link=True)
>
> or simply with
>
> class Employee(Person):
>     pass
>
> It you don't want/need control of the name of the 1to1 relationship
> between Employee and Person.
>
> Also, see
>
> http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefieldhttp://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-in...http://docs.djangoproject.com/en/dev/topics/db/models/#specifying-the...
>
> --
> Ramiro Morales

-- 
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: Best-practice for building URLs in templates with JavaScript

2011-04-23 Thread Shawn Milochik
On Sat, Apr 23, 2011 at 3:31 AM, Ryan Osborn  wrote:
> You could always make the payment_id group optional using a ?:
>
> update_payment/(?P\w+)?


Ryan,

Thanks. I considered that first, but rejected it because I want the
extra field to be required. If it's missing then it's an error. Giving
it a default in the view definition means extra code in all effected
views, which isn't DRY. Also a bug caused by missing parameters that
cause an error is more subtle than the (admittedly ugly) "duplicate"
url pattern.

I was hoping that, since the url tag, named URLs, and URLs with extra
parameters are all baked-in parts of Django that Django would have a
canonical way to deal with this, since URLs built based on user
actions are a very old technique. It seems like someone must have run
into this before me.

It occurs to me now that I could just use a placeholder, and replace
that in JavaScript:
Update Payment

Then use the JavaScript to replace the string 'payment_id' (or a regex
on its location in the URL) when the user takes action. It also moves
all of the logic out of views and urls, which I think is probably
best.

Shawn

-- 
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: extending a shopping cart

2011-04-23 Thread Shawn Milochik
Did you check out the docs for adding a generic foreign key to your
model itself?

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



DjangoCon.eu tickets

2011-04-23 Thread Daniele Procida
Tickets are sold out - to my horror, because I've bought my tickets for
travel, having finally persuaded my employer to let me attend.

They must have sold out shortly after I bought my travel tickets,
because they were available when I bought them.

I've applied to be on the waiting list, but if anyone finds themselves
with a surplus ticket...

Daniele

-- 
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: extending a shopping cart

2011-04-23 Thread shofty
ok, answering my own question here, kind of.

attempt 1.
# get the objects for this content type, then choose the object by id
ct = ContentType.objects.get_for_model(app_label=app,
name=content_type)
p = ct.get_object_for_this_type(pk=object_id)

the above code works to get the object and allows me to add the object
to the cart.

im not sure why name=content_type works when model=content_type isnt
working.
its got to be to do with the line that populates content_type, which
is

form.fields['content_type'].widget.attrs['value'] =
ContentType.objects.get_for_model(SuspFitment)

so this is returning the name for the model, how would i go about
returning the model attribute?

-- 
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: extending a shopping cart

2011-04-23 Thread shofty
so the problem is definitely this line.

ct = ContentType.objects.get_for_model(SuspFitment)

this works and adds an item to the cart.
am i totally misunderstanding what i can do with ContentTypes?
is there a way to grab a contenttype when its passed as a string?

off to see if i can find some info on content types.


On Apr 23, 11:32 am, shofty  wrote:
> thanks, it looks like i have.
>
> i can't get it working though.
>
> so the idea is to get the app name, model and id of the object before
> submission to the cart.
>
>     form.fields['object_id'].widget.attrs['value'] = product.id
>     form.fields['content_type'].widget.attrs['value'] =
> ContentType.objects.get_for_model(SuspFitment)
>     form.fields['app'].widget.attrs['value'] =
> ContentType.objects.get_for_model(SuspFitment).app_label
>
> then in the cart i need to retrieve the particular item, check its not
> already in the cart and add it / update it etc...
>
> the following lines don't work, both found from googling this issue,
> since i can't work out what to do from the documentation. I've
> included my suspicion on whats happening, please tell me what i've
> misunderstood about these lines.
>
> attempt 1.
> # get the objects for this content type, then choose the object by id
>     ct = ContentType.objects.get_for_model(content_type)
>     p = ct.get_object_for_this_type(pk=object_id)
>
> attempt 2.
> # get the object by supplying app, model and id
>     p = ContentType.objects.get(app_label=app, model=content_type,
> id=object_id)
>
> not sure what im doing wrong, i need to get an object, i know its app/
> model/id.
>
> On Apr 22, 5:48 pm, Shawn Milochik  wrote:
>
>
>
>
>
>
>
> > I think you just re-invented generic foreign keys:
>
> >http://docs.djangoproject.com/en/1.3/ref/contrib/contenttypes/#generi...

-- 
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: logout problem - NameError - newbie

2011-04-23 Thread Jirka Vejrazka
Hi did you notice in tutorial (or docs) that view names in urls.py are
usually strings, not functions? So, if you use 'farewell' in urls.py,
you should be fine.

  HTH

 Jirka

On 22/04/2011, Marg Wilkinson  wrote:
> Hi,
>
> I'm a total newbie slogging my way through a tutorial. I've reached an
> impasse with logging off
>
> In views my code includes
>
> 
> from django.contrib.auth import logout
>
> def farewell(request):
> logout(request)
> return HttpResponseRedirect('/')
> ---
>
> and urls.py has the lines
>
> -
> urlpatterns = patterns('',
>  url(r'^admin/', include(admin.site.urls)),
>  url(r'^$', main_page),
>  url(r'^user/(\w+)/$', user_page),
>  url(r'^login/$', 'django.contrib.auth.views.login',
> {'template_name': 'registration/login.html'}),
>  url(r'^logout/$',farewell),
> 
>
>
> http://127.0.0.1:8000/farewell  (or anything after the 8000/)  gives
> me an error
> -
> Exception Value:
>
> name 'farewell' is not defined
> 
>
> OK  but farewell looks defined to me in views.py,so what am I
> missing?
>
> (BTW - originally I was trying to use logout for my def instead of
> farewell, with appropriate urls.py changes - same error except it
> specified that "logout" was not defined.)
>
> Can anyone please point a newbie in the right direction?
>
> --
> 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.
>
>

-- 
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: extending a shopping cart

2011-04-23 Thread shofty
thanks, it looks like i have.

i can't get it working though.

so the idea is to get the app name, model and id of the object before
submission to the cart.

form.fields['object_id'].widget.attrs['value'] = product.id
form.fields['content_type'].widget.attrs['value'] =
ContentType.objects.get_for_model(SuspFitment)
form.fields['app'].widget.attrs['value'] =
ContentType.objects.get_for_model(SuspFitment).app_label

then in the cart i need to retrieve the particular item, check its not
already in the cart and add it / update it etc...

the following lines don't work, both found from googling this issue,
since i can't work out what to do from the documentation. I've
included my suspicion on whats happening, please tell me what i've
misunderstood about these lines.

attempt 1.
# get the objects for this content type, then choose the object by id
ct = ContentType.objects.get_for_model(content_type)
p = ct.get_object_for_this_type(pk=object_id)

attempt 2.
# get the object by supplying app, model and id
p = ContentType.objects.get(app_label=app, model=content_type,
id=object_id)

not sure what im doing wrong, i need to get an object, i know its app/
model/id.


On Apr 22, 5:48 pm, Shawn Milochik  wrote:
> I think you just re-invented generic foreign keys:
>
> http://docs.djangoproject.com/en/1.3/ref/contrib/contenttypes/#generi...

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



Re: django 1.1 performance versus django 1.2 performance

2011-04-23 Thread Torsten Bronger
Hallöchen!

Russell Keith-Magee writes:

> [...]
>
> No - there isn't a plan to address this, because it isn't clear
> what "this" is.
>
> While it is known that there has been a slowdown between versions,
> that slowdown has been accompanied by a massive increase in
> functionality -- for example, the 1.1->1.2 transition introduced
> support for multiple databases. To the best of my knowledge, the
> performance slowdown highlighted by Eric at Djangocon was
> relatively small - 5-10%, not on the order of 30-50%
> slowdown. This matches with my personal experience of upgrading.

Does anybody have estimates or figures concerning the impact of
middleware?  I love the middleware framework and I make extensive
use of it but sometimes I'm afraid it slows down every request
significantly, especially if you have a project with cheap view
functions.

And then, the number of "canonical" middleware has increased between
Django versions as far as I can see.

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.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: Best-practice for building URLs in templates with JavaScript

2011-04-23 Thread Artur Wdowiarski
If it's quite a big project with lots of ajax, I'd say it's worth a try to 
serve your urls to the client in some reasonable way and then write an 
equivalent of reverse() in javascript.



On 23 kwi 2011, at 09:31, Ryan Osborn  wrote:

> You could always make the payment_id group optional using a ?:
> 
> update_payment/(?P\w+)?
> 
> that way this will match either:
> 
> update_payment/
> 
> or
> 
> update_payment/123
> 
> Hope that helps,
> 
> Ryan
> -- 
> 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.

-- 
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: Best-practice for building URLs in templates with JavaScript

2011-04-23 Thread Ryan Osborn
You could always make the payment_id group optional using a ?:

update_payment/(?P\w+)?

that way this will match either:

update_payment/

or

update_payment/123

Hope that helps,

Ryan

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