Need details re: deletion of a referenced model instance

2012-02-14 Thread Jeff Blaine
Hi all,

I'm having trouble detecting changes that happen to a M2M field behind the 
scenes: as a result of one of the *referenced objects being deleted*

I'm using Django 1.3.1 with PostgreSQL 8

Let's say we have the following simple proof of concept models:

class Topping(models.Model):
name = models.CharField()

class Pizza(models.Model):
name = models.CharField()
toppings = models.ManyToManyField(Topping, null=true, blank=true)

And this data established using those models:

TOPPING
id=1, name="Pepperoni"
id=2, name="Onion"
id=3, name="Mushroom"

PIZZA
id=1, name="foopizza"
toppings=1,2,3

Known Facts:

1. Deleting any Topping object (for example, deleting id=1, 
name="Pepperoni") also removes it from foopizza.toppings.  Good.
2. No m2m_changed signal is sent when 1 (above happens).  BAD.

How do I tie into "topping *object* was deleted (no longer for sale), 
perform custom code on ALL Pizza objects that referenced it" ?

Register a post_delete signal for Topping?  How do I refer to or find the 
Pizza objects that referred to it?

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



Re: Need details re: deletion of a referenced model instance

2012-02-15 Thread Jeff Blaine

>
> >> Known Facts:
> >>
> >> 1. Deleting any Topping object (for example, deleting id=1,
> >> name="Pepperoni") also removes it from foopizza.toppings.  Good.
> >> 2. No m2m_changed signal is sent when 1 (above happens).  BAD.
>
> ...
>
 

> Check this out ;)
> https://docs.djangoproject.com/en/dev/ref/signals/#m2m-change
> d
>
Already checked it out before posting.  See '2' above.

Bug report filed: https://code.djangoproject.com/ticket/17688 

Thank you Marc and Anssi!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/JbupoNJCMS0J.
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.



A little InlineModelAdmin help please?

2012-03-15 Thread Jeff Blaine
Easier for me to just draw you a picture:

   ++
   |   noodle   |
   ++
| |
| |
  +-+ ++
  ||
  ||
+---+   +--+
| foo 1 |   | foo 2|
|   |   |  |
| noodle ref|   | noodle ref   |--+
+---+   +--+  |
   |  |
   |  |
   |  |
++  +---+
| bar 1  |  | bar 2 |
||  |   |
| foo 2 ref  |  | foo 2 ref |
++  +---+

I have a ModelAdmin for model "noodle" displaying an
Inline already of model "foo".  Works fine.

However, I want that existing inline of "foo" to also show
the associated info from model bar:

NOODLE
FOO 1   foofield1foofield2
FOO 2   foofield1foofield2
  BAR 1barfield1barfield2
  BAR 2barfield1barfield2

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



Re: A little InlineModelAdmin help please?

2012-03-16 Thread Jeff Blaine
Thanks for the reply, Marc.

On Thursday, March 15, 2012 4:32:48 PM UTC-4, Jeff Blaine wrote:
>
> Easier for me to just draw you a picture:
>
>++
>|   noodle   |
>++
> | |
> | |
>   +-+ ++
>   ||
>   ||
> +---+   +--+
> | foo 1 |   | foo 2|
> |   |   |  |
> | noodle ref|   | noodle ref   |--+
> +---+   +--+  |
>|  |
>|  |
>|  |
> ++  +---+
> | bar 1  |  | bar 2 |
> ||  |   |
> | foo 2 ref  |  | foo 2 ref |
> ++  +---+
>
> I have a ModelAdmin for model "noodle" displaying an
> Inline already of model "foo".  Works fine.
>
> However, I want that existing inline of "foo" to also show
> the associated info from model bar:
>
> NOODLE
> FOO 1   foofield1foofield2
> FOO 2   foofield1foofield2
>   BAR 1barfield1barfield2
>   BAR 2barfield1barfield2
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/W_9glP8b-ZAJ.
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.



Logging works from 'manage.py shell', not from app

2012-04-13 Thread Jeff Blaine
Hi all. I'm stumped on something. Using logging via 'manage.py shell' is
working as expected. Using it in the webapp generates zero data and
zero errors.

NOTE: /var/log/hostdb.log is WORLD WRITABLE (in order to dodge any
permissions errors right now while debugging this)

My logging settings are as follows:

LOGGING = { 
'version': 1, 
'disable_existing_loggers': True, 
'formatters': { 
'verbose': { 
'format': '%(levelname)s %(asctime)s %(module)s %(process)d 
%(thread)d %(message)s' 
}, 
'simple': { 
'format': '%(levelname)s %(message)s' 
} 
}, 
'handlers': { 
'console': { 
'level':'DEBUG', 
'class':'logging.StreamHandler', 
'formatter': 'verbose' 
}, 
'logfile': { 
'level': 'DEBUG', 
'class': 'logging.handlers.WatchedFileHandler', 
'formatter': 'verbose', 
'filename': '/var/log/hostdb.log', 
'mode': 'a' 
} 
}, 
'loggers': { 
'django.request': { 
'handlers': ['logfile', 'console'], 
'level': 'DEBUG' 
} 
} 
} 

For example, the following works fine (shows up in /var/log/hostdb.log):

python manage.py shell
>> import logging
>> l = logging.getLogger('django.request')
>> l.info('this is info!')

Yet I get absolutely nothing logged when a click through pages of the app 
itself.

Any ideas?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/TKIfqpwWZcUJ.
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.



Confused by STATICFILES_DIRS not working

2011-12-16 Thread Jeff Blaine
I'm having a heck of a time getting STATICFILES_DIRS working.  If anyone 
could shed some light on this or just point me to the "All of your Django 
STATIC* Settings Clarified Completely Once and For All" blog post or 
somesuch, I would really appreciate it.

STATIC_ROOT = '' # DEFAULT
STATIC_URL = '/static/' # DEFAULT
STATICFILES_DIRS = ( 
'/django_sites/new_rcfhostdb/static',
) 

Proof the intended CSS file exists in STATICFILES_DIRS:

-rw-r--r-- 1 jblaine wheel 56360 Dec 14 19:06 
/django_sites/new_rcfhostdb/static/bootstrap.css 

I issue a GET /hostdb/ 

"ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the 
STATIC_ROOT setting" 

Fine.

STATIC_ROOT = '/tmp/SHUT_UP' 

That stops the 'ImproperlyConfigured' exception.

The various attempted stylesheet references (from my base.html template) 
and their 404 errors: 

 

[16/Dec/2011 10:53:04] "GET /bootstrap.css HTTP/1.1" 404 2146 

 

[16/Dec/2011 10:53:08] "GET /hostdb/bootstrap.css HTTP/1.1" 404 2146 

 

[16/Dec/2011 10:57:13] "GET /static/bootstrap.css HTTP/1.1" 404 1741 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/cSCoskQNgFYJ.
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: Confused by STATICFILES_DIRS not working

2011-12-16 Thread Jeff Blaine
On Friday, December 16, 2011 11:18:09 AM UTC-5, Tom Evans wrote:
>
> On Fri, Dec 16, 2011 at 4:17 PM, Tom Evans  wrote:
> >
> > 1) Is staticfiles in INSTALLED_APPS ?
>

Yes, django.contrib.staticfiles is in INSTALLED_APPS
 

> > 2) Is DEBUG=True?
>

Yes
 

> > 3) What is the output of:
> >  python manage.py findstatic bootstrap.css
>

 No matching file

4) Are you using runserver?
>
Yes
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/9AL6N0s1kO0J.
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.



pre_remove and post_remove "actions" not sent via m2m_changed signalling?

2012-01-18 Thread Jeff Blaine
Hi all,

http://dpaste.org/1vhf6/ 

With the following models.py, and the output seen further

down, can anyone explain why pre_remove and post_remove

"actions" are not happening when I remove an item from

a M2M relation?

class Interface(models.Model):
name = models.CharField('Interface',
primary_key=True,
max_length=80)

class Netgroup(models.Model):
name = models.CharField('Netgroup',
primary_key=True,
max_length=80)

interfaces = models.ManyToManyField(Interface,
null=True,
blank=True)

def __unicode__(self):
return self.name

from django.db.models.signals import m2m_changed

def tester(sender, **kwargs):
action = kwargs['action']
instance = kwargs['instance']
pk_set = kwargs['pk_set']
model = kwargs['model']
fd = open('/tmp/m2m.log', 'a+')
fd.write('%s on %s pk_set of %s is %s\n' % (action, instance, model, 
str(pk_set)))
fd.close()

m2m_changed.connect(tester, dispatch_uid="whatever")

#===
#
# IN ADMIN UI: Removed 'barley.foo.org' from jbtest2 which

#  had 4 interfaces (and then has 3, correctly)

#
#  Logs the following...

#

#  Where's the "remove" actions?
#
#===

pre_clear on instance jbtest2: pk_set of  is 
None
post_clear on instance jbtest2: pk_set of  is 
None
pre_add on instance jbtest2: pk_set of  is 
set([u'babylon.foo.org', u'ape.foo.org', u'baker.foo.org'])
post_add on instance jbtest2: pk_set of  is 
set([u'babylon.foo.org', u'ape.foo.org', u'baker.foo.org']) 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/6XAka0tznY4J.
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: pre_remove and post_remove "actions" not sent via m2m_changed signalling?

2012-01-18 Thread Jeff Blaine
Answering my own question:  https://code.djangoproject.com/ticket/16073

:(

Thanks to IRC #django-users : carljm and domguard

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/nPvLEW3RhVEJ.
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.



base.html (extended by others) has to be in project (not app) root?

2011-04-14 Thread Jeff Blaine
Django 1.3

Hi all,

I can't seem to get around this.  It appears that, the following 
"index.html" template in */whatever/myproject/myapp*

{% extends "base.html %}


Looks for base.html as /whatever/myproject/base.html instead 
of /whatever/myproject/myapp/base.html

My TEMPLATE_DIRS is set as follows, and with this setting, the 
*/whatever/myproject/myapp/index.html 
template is loaded fine* if I make it self-contained (not extending)

TEMPLATE_DIRS = (
'/whatever/myproject',
)

Any ideas?

-- 
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: base.html (extended by others) has to be in project (not app) root?

2011-04-14 Thread Jeff Blaine
Gladys,

On Thursday, April 14, 2011 4:12:29 PM UTC-4, gladys wrote:
The root directory for your templates is in  '/whatever/myproject', so 
>
> of course it will look for your base.html here. 
> Now if your base is in another location, say "/whatever/myproject/ 
> myapp/base.html", your extends should look like this: 
> {% extends "myapp/base.html" %}. 
>

First, thanks for the reply.

It's *finding* my /myproject/myapp/*index.html* template (the one that calls 
"base.html"), so something clearly knows about where to find my templates, 
yet "extend" looks elsewhere.

That is, if I make /myproject/myapp/index.html to be completely 
self-contained, it is found and loaded fine.

If I change it to {% extend "base.html" %}, it can't find that referenced 
template.

That seems broken to me.

I tried your suggestion above (the other day, and again now) in 
/myproject/myapp/index.html

{% extend "myapp/base.html" %}

It does not work:

Caught TemplateDoesNotExist while rendering: myapp/base.html

ALSO... I changed the following from:

TEMPLATE_DIRS = (
'/myproject',
)

to:

TEMPLATE_DIRS = (
'/myproject/myapp',
)

Which then results in failure to find even /myproject/myapp/index.html

TemplateDoesNotExist at /

 

>
> Best of Luck. 
>
> -- 
> Gladys 
> http://blog.bixly.com 
>
>
> On Apr 15, 3:56 am, Jeff Blaine  wrote: 
> > Django 1.3 
> > 
> > Hi all, 
> > 
> > I can't seem to get around this.  It appears that, the following 
> > "index.html" template in */whatever/myproject/myapp* 
> > 
> > {% extends "base.html %} 
> >  
> > 
> > Looks for base.html as /whatever/myproject/base.html instead 
> > of /whatever/myproject/myapp/base.html 
> > 
> > My TEMPLATE_DIRS is set as follows, and with this setting, the 
> */whatever/myproject/myapp/index.html 
> > template is loaded fine* if I make it self-contained (not extending) 
> > 
> > TEMPLATE_DIRS = ( 
> > '/whatever/myproject', 
> > ) 
> > 
> > Any ideas?

-- 
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: base.html (extended by others) has to be in project (not app) root?

2011-04-15 Thread Jeff Blaine
Thank you all.  I will digest the replies when I have the time to properly 
focus back on the issue (it's obviously small, since I have a workaround in 
place by shoving base.html into the project root).

It still, regardless of solutions, even in light of the words shared in this 
thread (which I've only skimmed for now), makes no sense to me how it's "the 
right thing" that my index.html is found but base.html cannot be found just 
because it is referenced by "extend".  I will have to decide for the 
time-being that there's some underlying good reason/concept that I just am 
not savvy to.

You found index.html fine!  It says in it to extend "base.html"!  Find it in 
the same place you found index.html!

-- 
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: base.html (extended by others) has to be in project (not app) root?

2011-04-15 Thread Jeff Blaine
On Friday, April 15, 2011 4:21:56 PM UTC-4, Brian Neal wrote:
>
> You didn't post how you loaded the template in your view function. In 
> particular, what path string you used. 
>

Ah.  The missing piece to bring order to all of this confusion on my 
part.

I was using "myapp/index.html", per Tutorial 3's example.

Obviously (now), this is what was allowing my index.html to be found when 
using
TEMPLATE_DIRS = ('/myproject',)

... and also what was causing the app to expect to find "base.html" in
/myproject and not /myproject/myapp

And my failure to be able to use {% extend "myapp/base.html %} with my
TEMPLATE_DIR set as above was because... I had not MOVED IT to
myapp.  Geez.

This all makes perfect sense to me now and I have it working as I wanted it 
to.

Thank you all again for the help.

In any event, this isn't magic. I suggest you read this section of the 
> docs: 
>
> http://docs.djangoproject.com/en/1.3/ref/templates/api/#loading-templates 
>
> In particular, pay attention to the TEMPLATE_DIRS and TEMPLATE_LOADERS 
> settings in your project. Those settings control the template search 
> order. 
>
> Best, 
> BN

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



Put an "inline" at the top of admin form instead of bottom?

2011-04-15 Thread Jeff Blaine
I'm using the admin functionality for most of my needs (a nice CRUD DB 
frontend, not a user-facing website).  Is there a best way to get one of my 
inline models presented at the top of the form instead of the bottom?  I 
would greatly prefer not to have to specify all of the fields (via 
ModelAdmin.fields), as we really like the automatic introspection 
functionality.

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



Cannot submit tickets - always marked as spam!

2011-04-19 Thread Jeff Blaine
I've tried twice now to interact with the Django trac.  Last week and just 
now.  Both resulted in:

badip:state/blacklist.d/127.0.0.1

Please tell me what I am doing wrong.

-- 
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: website path

2011-04-19 Thread Jeff Blaine
I imagine you need to configure your urls.py

I suggest going through the whole tutorial, starting at the following page. 
 This is all
explained there.

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

-- 
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: Why i can reach my media files from my static url?

2011-04-19 Thread Jeff Blaine
Please show your settings:

STATIC_ROOT
STATICFILES_DIR
STATIC_URL
MEDIA_ROOT
MEDIA_URL

-- 
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: website path

2011-04-19 Thread Jeff Blaine
How to avoid hardcoding URL paths in your templates:

http://docs.djangoproject.com/en/1.3/ref/templates/builtins/#url

Maybe that helps some?

I don't think I can be of more help.  I'm too new.

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



.save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jeff Blaine
How is this possible based on the model below?

d = Device()
d.save()
# no errors

class Device(models.Model):

propertyno  = models.CharField('Property Number',
   max_length=10,
   primary_key=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.



Re: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jeff Blaine
"If Django sees you've explicitly set 
Field.primary_key,
 
it won't add the automatic id column."

http://docs.djangoproject.com/en/1.3/topics/db/models/#automatic-primary-key-fields

-- 
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: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jeff Blaine
A specified primary_key should not be auto-incrementing from my 
understanding.  The following shows 2 objects with the same value for a 
field I specified should be the primary_key:

>>> from hostdb.models import Device
>>> d = Device()
>>> d.propertyno
''
>>> d.save()
>>> d = Device()
>>> d.propertyno
''
>>> d.save()
>>>

-- 
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: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jeff Blaine
"primary_key=True implies 
null=False
 and 
unique=True.
 
Only one primary key is allowed on an object."

So that unique=True part is inaccurate?  Or is that, again, another thing 
that will fail only at validation?

This seems pretty broken to me :(

-- 
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: .save() works with no (custom, not 'id') primary key specified?

2011-04-29 Thread Jeff Blaine
Thank you both.  That's a great explanation, Jacob.  I'll consider your 
message more closely and play around on Monday a bit.

PS: I said it *seems* broken to me, as in "Maybe I just don't understand the 
reason.", which I clearly didn't :)

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



Stuck at integration step w/ WSGI

2011-05-03 Thread Jeff Blaine
I've read the following and am still stuck and wondering what piece of this 
puzzle
I am missing.  If anyone has any ideas, please do comment!

http://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

Using the Django 1.3 development webserver, everything works fine. 
 Migrating to
Apache 2.x with WSGI 3.3, not so much.  The WSGI part of the picture seems 
to
function as intended, but not with my Django stuff.

Visiting / gives me the *expected* 404 (see urls.py below)

Visiting /admin (which is really the entirety of my needs) gives me: "Site 
matching query does not exist."

--- BEGIN Apache config --

  ServerName rcf-hostdb.our.org

  # A single dir with nothing else but our WSGI wrapper, for security
  
Order allow,deny
Allow from all
  

  # Handle all requests via the WSGI wrapper, django.wsgi
  WSGIScriptAlias / 
/rcfwebapps/apps/hostdb/hostdb_project/apache/django.wsgi

  # And one other directory for storing static files, like CSS, favicon.ico
  
Order deny,allow
Allow from all
  

  # Now redefine where to find those static files (not via WSGI)
  Alias /robots.txt /rcfwebapps/apps/hostdb/hostdb_project/static/robots.txt
  Alias /favicon.ico 
/rcfwebapps/apps/hostdb/hostdb_project/static/favicon.ico
  AliasMatch ^/([^/]*\.css) 
/rcfwebapps/apps/hostdb/hostdb_project/static/styles/$1
  Alias /media/ /rcfwebapps/apps/hostdb/hostdb_project/static/media/


-- END Apache Config -

-- BEGIN url mapping -
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
)
-- END url mapping -

-- BEGIN apache/django.wsgi 
#!/rcfwebapps/apps/hostdb/bin/python import os import sys path = 
'/rcfwebapps/apps/hostdb' if path not in sys.path: sys.path.append(path) 
os.environ['DJANGO_SETTINGS_MODULE'] = 'hostdb_project.settings' 
os.environ['PYTHON_EGG_CACHE'] = '/rcfwebapps/apps/hostdb/egg-cache' import 
django.core.handlers.wsgi application = 
django.core.handlers.wsgi.WSGIHandler()
--- END django.wsgi 

My "site" directory tree is as follows (the site is 'hostdb_project' with 1 
app named
'hostdb'):

 |-agent--
 |-apache-
 |
 ||-admin|-hostdb-
 |-hostdb-|-fixtures-
|-hostdb_project-||-static---
 |
 |   |-css (symlink to 
django/contrib/admin/media/css)
 |-static-|-media|-img (symlink to 
django/contrib/admin/media/img)
  |  |-js (symlink to 
django/contrib/admin/media/js)
  |-styles---

Full exception copy/paste:

Environment: Request Method: GET Request URL: 
http://rcf-hostdb.our.org/admin/ Django Version: 1.3 Python Version: 2.7.1 
Installed Applications: ['django.contrib.auth', 
'django.contrib.contenttypes', 'django.contrib.sessions', 
'django.contrib.sites', 'django.contrib.messages', 
'django.contrib.staticfiles', 'hostdb', 'django.contrib.admin'] Installed 
Middleware: ('django.middleware.common.CommonMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware') Traceback: File 
"/rcfwebapps/apps/hostdb/lib/python2.7/site-packages/django/core/handlers/base.py"
 
in get_response 111. response = callback(request, *callback_args, 
**callback_kwargs) File 
"/rcfwebapps/apps/hostdb/lib/python2.7/site-packages/django/contrib/admin/sites.py"
 
in wrapper 214. return self.admin_view(view, cacheable)(*args, **kwargs) 
File 
"/rcfwebapps/apps/hostdb/lib/python2.7/site-packages/django/utils/decorators.py"
 
in _wrapped_view 93. response = view_func(request, *args, **kwargs) File 
"/rcfwebapps/apps/hostdb/lib/python2.7/site-packages/django/views/decorators/cache.py"
 
in _wrapped_view_func 79. response = view_func(request, *args, **kwargs) 
File 
"/rcfwebapps/apps/hostdb/lib/python2.7/site-packages/django/contrib/admin/sites.py"
 
in inner 196. return self.login(request) File 
"/rcfwebapps/apps/hostdb/lib/python2.7/site-packages/django/views/decorators/cache.py"
 
in _wrapped_view_func 79. response = view_func(request, *args, **kwargs) 
File 
"/rcfwebapps/apps/hostdb/lib/python2.7/site-packages/django/contrib/admin/sites.py"
 
in login 331. return login(request, **defaults) File 
"/rcfwebapps/apps/hostdb/lib/python2.7/site-packages/django/utils/decorators.py"
 
in _wrapped_view 93. response = view_func(request, *args, **kwargs) File 
"/rcfwebapps/apps/hostdb/lib/python2.7/site-packages/django/views/decorators/cache.py"
 
in _wrapped_view_func 79. response = view_func(request, *args, **kwargs) 
File 
"/rcfwebapps/apps/hostdb/lib/python2.7/site-packages/django/contrib/auth/views.py"
 
in login 59. current_site = get_current_site(request) File 
"/rcfwebapps/apps/hostd

Re: Stuck at integration step w/ WSGI

2011-05-03 Thread Jeff Blaine
On Tuesday, May 3, 2011 2:03:14 PM UTC-4, Daniel Roseman wrote:
>
> I don't know why you think this is a WSGI error. As you say, Apache is 
> finding your WSGI app with no problem, and the error you get is a Django one 
> - you simply don't seem to have any data in your Site table, whereas the 
> Django admin requires one.
>

Daniel, thanks for taking time out to reply.

I didn't say it was a WSGI error.  I said I am stuck at the WSGI integration 
step and "The WSGI part of the picture seems to function as intended, but 
not with my Django stuff."

Note too that I said Django admin works fine with the same database via the 
development webserver.  If "Django admin" requires something I am missing, I 
would not expect it to work under the development server, but I'm eager to 
learn anything you can share.

 

-- 
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: Stuck at integration step w/ WSGI

2011-05-03 Thread Jeff Blaine
Also, adding an example.com site (via /admin via dev server) doesn't change 
the behavior.  Same error.  I'm not sure if that's what you were suggesting 
to do or not.

-- 
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: Stuck at integration step w/ WSGI

2011-05-03 Thread Jeff Blaine
I'd certainly like to hear more about this, but I got it all working fine by 
commenting out 'django.contrib.sites' from INSTALLED_APPS

That's obviously not the right 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: Stuck at integration step w/ WSGI

2011-05-03 Thread Jeff Blaine
On Tuesday, May 3, 2011 4:42:25 PM UTC-4, Jacob Kaplan-Moss wrote:
>
> Hi Jeff --
>
> To make the admin work w/r/t sites, you'll need three things:
>
> * An entry in the sites table.
> * A setting SITE_ID set to the ID of the Site entry you'd like to use
> (i.e. SITE_ID = 1).
> * `django.contrib.sites` in your INSTALLED_APPS
>

Thanks Jacob -- does the site entry in the database have to be anything 
specific?  We don't really use that.  Just put any old thing in there via 
Admin in the development server?

I have a SITE_ID = 1 in settings.py from, I assume, when the project was 
made.  I suspect when I deleted the 'example.com' site last week, that broke 
the relationship, no?

-- 
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: Stuck at integration step w/ WSGI

2011-05-03 Thread Jeff Blaine
On Tuesday, May 3, 2011 6:33:20 PM UTC-4, Jacob Kaplan-Moss wrote:
>
> On Tue, May 3, 2011 at 5:07 PM, Jeff Blaine  wrote:
> > Thanks Jacob -- does the site entry in the database have to be anything
> > specific?  We don't really use that.  Just put any old thing in there via
> > Admin in the development server?
>
> Well, if you want all the parts of the admin to work correctly
> (especially those "view on site" buttons and similar features) you
> probably should set the entry to something that actually exists.
>
Ah, I wasn't aware of such features.  We're using "Admin AS the site" due to 
our
needs for a direct web front-end to a database without custom "content" as 
it
were or media of any sorts.  It's a host/asset database for internal use by 
20
people.  For now, we'd rather not be writing load of templates that almost
completely reproduce what 'Admin' gives us already.  That may change, and
if it does, I understand the point of 'Sites' now as they relate to the 
admin
interface.  I also went and read the reference doc on sites.

Thank you.

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



REMOTE_USER authentication to 'Admin'?

2011-05-17 Thread Jeff Blaine
Hi folks,

I'm successfully using Apache with mod_authnz_ldap, WSGI, Django 1.3.  If I 
hit
'/admin', I get asked to authenticate (BasicAuth done through LDAP).  I 
succeed.
However, this just results in me then seeing the Django admin login screen 
instead
of logging me in to Admin.

What am I missing?

Apache relevant portion
===

# If this directive is set, the value of the REMOTE_USER environment 
variable will be set
# to the value of the attribute specified.
AuthLDAPRemoteUserAttribute uid

Django
==

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

# Try django auth first, failover to LDAP
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'django.contrib.auth.backends.RemoteUserBackend',
)

-- 
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: REMOTE_USER authentication to 'Admin'?

2011-05-17 Thread Jeff Blaine
[ *sigh* - I wish the web UI to google groups had an 80-column marker. ]
[ Sorry for the formatting in the previous message.  I'm used to hitting ]
[ enter. ]

Thanks for the reply, Jacob.

That gets us somewhere, because authenticating to Apache/LDAP as jblaine
did NOT make a Django user jblaine.

So that's one part of the problem.

The second is that creating jblaine by hand, and setting it is_staff and 
also
superuser, did not then do anything.  I authenticate to Apache/LDAP fine
then see the Django 'Admin' login screen with empty username/password
form fields.

Here's the whole Apache Directory section for the WSGI, in case something
jumps out:

  
AuthType Basic
AuthName "G06A Host Database: Secure"
AuthBasicProvider ldap
AuthzLDAPAuthoritative off
AuthLDAPRemoteUserAttribute uid
AuthLDAPUrl "ldap://ldap-prod.our.org:389/o=our.org";
Require ldap-attribute departmentname=RCF
Order allow,deny
Allow from all
  

Any clever ideas for where to shim some debugging code to see what is
happening in the native Django stuff?

-- 
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: REMOTE_USER authentication to 'Admin'?

2011-05-17 Thread Jeff Blaine
On Tuesday, May 17, 2011 3:10:03 PM UTC-4, Jacob Kaplan-Moss wrote:
>
> On Tue, May 17, 2011 at 2:00 PM, Jeff Blaine  wrote:
> > That gets us somewhere, because authenticating to Apache/LDAP as jblaine
> > did NOT make a Django user jblaine.
>
> That's interesting - perhaps LDAP is reporting a different username?
> You could check in the auth_user table to see what's getting created
> when you authenticate; you should see a entry get created the first
> time you authenticate as a given user
>
I guess I'll start the debugging then, because:

DELETE FROM auth_user WHERE username != 'admin';
Query OK, 1 row affected (0.00 sec)

Auth to Apache/LDAP as jblaine, get Admin login screen.

mysql> SELECT username FROM auth_user;
+--+
| username |
+--+
| admin|
+--+
1 row in set (0.00 sec)

mysql>

-- 
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: REMOTE_USER authentication to 'Admin'?

2011-05-17 Thread Jeff Blaine
Also, FWIW, the REMOTE_USER is definitely getting set to 'jblaine'

1xx.xx.xx.231 - jblaine [17/May/2011:16:12:41 -0400] "GET 
/static/admin/img/admin/nav-bg.gif HTTP/1.1" 200 273 
"http://rcf-hostdb.our.org/admin/"; "Mozilla/4.0 (compatible; MSIE 7.0; 
Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 
3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)"

-- 
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: REMOTE_USER authentication to 'Admin'?

2011-05-18 Thread Jeff Blaine
I'm failing so far.

I copied backends.py to my project root as mybackends.py

I edited it and renamed ModelBackend to MyModelBackend

I changed RemoteUserBackend(ModelBackend)
to MyRemoteUserBackend(MyModelBackend)

I changed settings.py to:

AUTHENTICATION_BACKENDS = (
'mybackends.MyRemoteUserBackend',
)

"validate" showed 0 errors

I restarted Apache

Authenticating to Apache/LDAP does not trigger any of my debugging
code in MyRemoteUserBackend, I get no errors/exceptions, and I
still just see the Admin login screen at the end.

In fact, I have the following to log that mybackends.py even gets
imported:

import os

fd = open('/tmp/auth.log', 'w')
fd.write('imported file at least\n')
fd.flush()
os.fsync()
fd.close()

Yet, /tmp/auth.log is still sitting empty just as I made it and
chown()ed it:

rcfhostdb:rcfwebapps> ls -ld /tmp/auth.log
-rw-r--r-- 1 apache wheel 0 May 18 19:36 /tmp/auth.log
rcfhostdb:rcfwebapps>

-- 
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: REMOTE_USER authentication to 'Admin'?

2011-05-19 Thread Jeff Blaine
I'm kind of at the point where I consider this a bug in some fashion, 
regardless
of my specific problem (which persists).

AUTHENTICATION_BACKENDS = (
'mybackends.MyRemoteUserBackend',
)

If I define AUTHENTICATION_BACKENDS in settings, no default fallen
back on.  If my hand-specified stuff doesn't work, the site should fail to 
run.
It would appear that Django is just blindly ignoring
mybackends.MyRemoteUserBackend with zero error/log information,
then proceeding to use its own.

rcfhostdb:rcfwebapps> python -c "import mybackends"
Loaded settings.  # from print to sys.stderr in settings.py
In mybackends.  # from print to sys.stderr in mybackends.py
rcfhostdb:rcfwebapps>

When I visit /admin with a browser, authenticate to Apache/LDAP and then
get the normal Admin login screen, error_log shows the following:

[Thu May 19 16:55:54 2011] [error] Loaded settings.

-- 
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: REMOTE_USER authentication to 'Admin'?

2011-05-19 Thread Jeff Blaine
Thanks Jacob and Ramiro.

I finally figured it out, and unfortunately it was, of course, something 
stupid :(

I had changed the directory name holding my WSGI app and had not changed the
Apache config's path reference in *both* places (ScriptAlias and 
Directory).  SIGH.
That was causing the static file requests to show up in access_log as from 
'jblaine',
which made me think all auth was working properly, when in fact it wasn't. 
 It just
took me to finally notice that there were requests from '-' and 'jblaine' in 
the same
session full of requests.  I'm a little surprised I even noticed finally.

Additionally, as Jacob pointed out, I needed my own configure_user to
set default permissions to get any login access to Admin for auto-created
users.

Sweet:

[Thu May 19 23:31:36 2011] [error] in MyRemoteUserBackend.authenticate()
[Thu May 19 23:31:36 2011] [error] Remote user is jblaine
[Thu May 19 23:31:36 2011] [error] Remote user cleaned is jblaine
[Thu May 19 23:31:36 2011] [error] Trying to create jblaine
[Thu May 19 23:31:36 2011] [error] Created jblaine
[Thu May 19 23:31:36 2011] [error] in MyRemoteUserBackend.configure_user()
[Thu May 19 23:31:37 2011] [error] Set jblaine is_staff and is_superuser 
True

Now I have the problem where "Logout" from Admin actually does not do
much of anything because REMOTE_USER is still set in the browser and all
someone has to do is revisit /admin with the same browser instance and they
get automatically logged right back in without a password.

But I'll take that after this victory.  Thanks Jacob and Ramiro!

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



Making command-line clients to Django data

2011-06-13 Thread Jeff Blaine
We've got our Django site complete for now.  It consists entirely of just a 
customized
default "admin" setup.

We'd like to develop some command-line interfaces to the data.

Is there a good/best approach to doing this?  Can I (recommended?) use 
templates
for formatting text to the terminal?

Any tips, links, etc, would be appreciated.

PS: I'm aware of (but not interested in) the ability to extend manage.py 
with more
commands.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/0PDkFKZmpfgJ.
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: Making command-line clients to Django data

2011-06-13 Thread Jeff Blaine

>
> Why not? To want a decent CLI integrated with your app, but without using 
> management commands, is a pretty dumb idea.
>

It's not how we want the end-users to interface with it.

Why is it a dumb idea? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/EzAXCoD5KasJ.
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 do I access a field's verbose_name?

2011-06-20 Thread Jeff Blaine
I'd like to make use of a field's verbose_name in some code instead of
duplicating that sort of info.  Can someone show me how?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/aapHSFviGXcJ.
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 do I access a field's verbose_name?

2011-06-20 Thread Jeff Blaine
On Monday, June 20, 2011 11:56:00 AM UTC-4, Shawn Milochik wrote:
>
> On 06/20/2011 11:54 AM, Jeff Blaine wrote:
> > I'd like to make use of a field's verbose_name in some code instead of
> > duplicating that sort of info.  Can someone show me how?
> >
>
> your_object._meta.verbose_name
>
> Check out _meta in manage.py shell -- lots of good stuff in there.
>

That's the model's verbose_name

I want a field's verbose_name (see subject)

[ Thanks for replying though ]

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/RVDdSPes7zAJ.
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 do I access a field's verbose_name?

2011-06-20 Thread Jeff Blaine
Thanks all.

For anyone coming across this later, some enlightening noodling.  All sorts 
of good
stuff in there, as Shawn indicated!

>>> from hostdb.models import Device
>>> dir(Device._meta)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', 
'__getattribute__', '__hash__', '__init__', '__module__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', 
'__str__', '__subclasshook__', '__weakref__', '_field_cache', 
'_field_name_cache', '_fields', '_fill_fields_cache', '_fill_m2m_cache', 
'_fill_related_many_to_many_cache', '_fill_related_objects_cache', 
'_join_cache', '_m2m_cache', '_many_to_many', '_name_map', '_prepare', 
'_related_many_to_many_cache', '_related_objects_cache', 'abstract', 
'abstract_managers', 'add_field', 'add_virtual_field', 'admin', 'app_label', 
'auto_created', 'auto_field', 'concrete_managers', 'contribute_to_class', 
'db_table', 'db_tablespace', 'duplicate_targets', 'fields', 
'get_add_permission', 'get_all_field_names', 
'get_all_related_m2m_objects_with_model', 
'get_all_related_many_to_many_objects', 'get_all_related_objects', 
'get_all_related_objects_with_model', 'get_ancestor_link', 'get_base_chain', 
'get_change_permission', 'get_delete_permission', 'get_field', 
'get_field_by_name', 'get_fields_with_model', 'get_latest_by', 
'get_m2m_with_model', 'get_ordered_objects', 'get_parent_list', 
'has_auto_field', 'init_name_map', 'installed', 'local_fields', 
'local_many_to_many', 'managed', 'many_to_many', 'module_name', 
'object_name', 'order_with_respect_to', 'ordering', 'parents', 
'permissions', 'pk', 'pk_index', 'proxy', 'proxy_for_model', 
'related_fkey_lookups', 'setup_pk', 'setup_proxy', 'unique_together', 
'verbose_name', 'verbose_name_plural', 'verbose_name_raw', 'virtual_fields']
>>> type(Device._meta.fields[0])

>>> type(Device._meta.fields[13])

>>> Device._meta.fields[13].verbose_name
'Cores per Processor'
>>> Device._meta.get_field('cores_per_proc')

>>> Device._meta.get_field('cores_per_proc').verbose_name
'Cores per Processor'
>>> Device._meta.pk.name
'id'
>>> Device._meta.many_to_many
[, 
]
>>> for i in Device._meta.many_to_many: print i.name
...
tags
netgroups
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/m62nARMjJ10J.
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 do I access a field's verbose_name?

2011-06-20 Thread Jeff Blaine
Here's what I came up with, in case someone else finds this useful.

I'm quite proud, actually.

from django.core.management.base import BaseCommand, CommandError
from hostdb.models import Device, Interface

def sanitized_value(v):
if v == None:
return ""
return v

class Command(BaseCommand):
args = ''
help = 'Display host information for the specified host(s)'

def handle(self, *args, **options):
for hostname in args:
if hostname.find('.mitre.org') == -1:
hostname = hostname + '.mitre.org'
try:
dev = Interface.objects.get(fqdn=hostname).device
except Device.DoesNotExist:
raise CommandError('Host "%s" does not exist' % hostname)

# pk, the object defining the primary key of our model
pk = Device._meta.pk

# We turn this on because we know in our case our pk is "id"
# which is pointless to print out in this context
skip_pk = True

# Iterate over all field objects (ManyToMany are not included
# in this for some reason), in the order they are defined
# in the model (thankfully!).
for field in Device._meta.fields:
if (field == pk) and skip_pk: continue
vname = field.verbose_name
val = sanitized_value(field.value_from_object(dev))
self.stdout.write("%s: %s\n" % (vname, val))

# Now handle the ManyToMany fields
for field in dev._meta.many_to_many:
m2m_manager = getattr(dev, field.name)
vname = field.verbose_name
l = []
# Using ','.join(m2m_manager.all()) doesn't work because
# ManyRelatedManager objects are not iterable.  We have to do 
this.
for t in m2m_manager.all():
l.append(str(t))
val = ','.join(l)
self.stdout.write("%s: %s\n" % (vname, val))

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/uPCHH_GqFDcJ.
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.



Strange value_from_object() return value (2L returned instead of unicode string)

2011-06-20 Thread Jeff Blaine
I can't seem to figure out what is causing this:  According to the following 
2 models
and the 'python manage.py shell' session shown after them, I am getting 2L 
as a
return value from a certain call when I would expect u'redhat 5.6' or 
similar.

If anyone has any ideas, please let me know.  I am very stumped at this 
point.

I include (and query) "Status" just to show normal/expected output from a 
very
similar query for a field value.

class Status(models.Model):
name= models.CharField('Status',
   max_length=30,
   primary_key=True)

def __unicode__(self):
return self.name

class Distro(models.Model):
# don't make name the primary key, because then it has to be
# unique and we want to allow multiple items with the same
# 'name', like ubuntu 10.10 and ubuntu 11.04
name= models.CharField('Distro Brand',
   help_text='redhat, ubuntu, etc',
   max_length=30)

version = models.CharField('Distro Version',
   help_text='Not kernel version',
   max_length=10)

def __unicode__(self):
return u"%s %s" % (self.name, self.version)

=

>>> from hostdb.models import Device, Interface
>>> hostname = 'beijing.mitre.org'
>>> dev = Interface.objects.get(fqdn=hostname).device
>>> dev.status

>>> f = dev._meta.get_field('status')
>>> f.value_from_object(dev)
u'Online'
>>> # Super -- this is exactly what I would expect.  Now trouble
>>> dev.distro

>>> print dev.distro
redhat 5.6
>>> f = dev._meta.get_field('distro')
>>> f.value_from_object(dev)
2L
>>> # what the hell?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/BEubx9rDBd0J.
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: Strange value_from_object() return value (2L returned instead of unicode string)

2011-06-20 Thread Jeff Blaine
PS: Django 1.3

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Moc8-Pa5qJ4J.
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: Strange value_from_object() return value (2L returned instead of unicode string)

2011-06-21 Thread Jeff Blaine
Yes, seems that way, Malcom, but *why*

class Device(models.Model):
# ...
status  = models.ForeignKey(Status,
blank=True,
null=True,
verbose_name="Status",
on_delete=models.DO_NOTHING)

distro  = models.ForeignKey(Distro,
blank=True,
null=True,
verbose_name="Distro",
on_delete=models.DO_NOTHING)
# ...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/e24WN7NmnxEJ.
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: Strange value_from_object() return value (2L returned instead of unicode string)

2011-06-21 Thread Jeff Blaine
Okay, here's the problem.

>>> f = dev._meta.get_field('distro')
>>> f.value_from_object(dev)
2L

value_from_object is defined as:


def value_from_object(self, obj):
"Returns the value of this field in the given model instance."
return getattr(obj, self.attname)


>>> f.attname
'distro_id'
>>>

As others guessed, value_from_object() is returning the pk ID in this
case.

Model "Distro" is the only model of mine showing this behavior, as it is the
only foreign key "target" model I have defined without named primary key.

>From what I can tell, value_from_object() is actually mis-named, and should
be named pkvalue_from_object(), no?  Or is there some case where 
self.attname
for a field is *not* set to the primary key attribute name?

Any ideas?  I really want (concept) 
"myfield.unicode_representation_of_object(myobject)"

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/VwIWznE_R-QJ.
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: Strange value_from_object() return value (2L returned instead of unicode string)

2011-06-21 Thread Jeff Blaine
On Tuesday, June 21, 2011 11:00:37 AM UTC-4, Tom Evans wrote:
>
> On Tue, Jun 21, 2011 at 3:47 PM, Jeff Blaine  wrote:
> > Any ideas?  I really want (concept)
> > "myfield.unicode_representation_of_object(myobject)"
> >
>
> unicode(myobject.myfield) // unicode(getattr(myobject, 'myfield'))
>
> Am I being dense?
>
Nope, you're just dealing with a newbie.  The second form works perfectly
for my needs.  Thanks! 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ISb3Re7hHYYJ.
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: Strange value_from_object() return value (2L returned instead of unicode string)

2011-06-21 Thread Jeff Blaine

>
> But why do you need to get that value via the *field* object? The usual way 
> to do it is simply to access the attribute directly on the model instance:
>
> unicode(dev.distro)
>
> or, if you have the field name as a string as you imply originally, use 
> `getattr`:
>
> unicode(getattr(dev, 'distro'))
>

Indeed, that's what I am doing now:

for field in Device._meta.fields:
vname = field.verbose_name
val = unicode(getattr(dev, field.name))
val = sanitized_value(val)
self.stdout.write("%s: %s\n" % (vname, val))
 
Thank you all.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/vTfXKM6K914J.
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: Making command-line clients to Django data

2011-06-24 Thread Jeff Blaine
Just a follow-up:

Well, I took your advice and did it via manage command(s) with wrapper 
scripts
for the users.  It's working well so far.  I do wish I had a clearer 
understanding
of what the downside to the "standalone" method is, but I suspect I will 
never
know unless I go out of my way and try it myself.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/0GNE80cCQmcJ.
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: REMOTE_USER authentication to 'Admin'?

2011-06-27 Thread Jeff Blaine
Sorry, I have no knowledge of Oracle SSO, what it allows, how it works, etc.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/kFeKEvDSqZYJ.
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: REMOTE_USER authentication to 'Admin'?

2011-06-28 Thread Jeff Blaine
It's all right here:

https://docs.djangoproject.com/en/1.3/howto/auth-remote-user/

and other details in the mailing list thread you are reading/posting to 
(this one!)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/C9RWSjahsY4J.
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.



ManyRelatedManager.add() acting funny?

2011-08-13 Thread Jeff Blaine
What happened here?  Do I not understand .add()?  I would have expected to 
see
[(u'rcf_clients',)] not [(u'rcf_clients', u'')]

>>> print d.tags.values_list()
[]
>>> d.tags.add('rcf_clients')
>>> d.save()
>>> print d.tags.values_list()
[(u'rcf_clients', u'')]
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/UD_riTfXZXsJ.
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: ManyRelatedManager.add() acting funny?

2011-08-13 Thread Jeff Blaine
Nevermind.  I get it.  'tags' has another field, description, which is what 
the extra u'' is for.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/jnvlX18nWtwJ.
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.