Opened 16 years ago
Last modified 10 years ago
#10405 closed
quoted class names in foreign key definition causes 'str' object has no attribute '_default_manager' — at Initial Version
Reported by: | danbrwn | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | Normal | Keywords: | foreign, key, quoted, dceu2011 |
Cc: | Ramiro Morales, jamespic@…, subsume@…, tom@…, eduardocereto@…, djsnickles@…, michaelvantellingen@…, seocam@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Myself and another discovered the following error with the code shown. In both cases we had quoted strings for reference class. In both cases importing the specific class and then referencing without the quotes solved the problem. I tried through IRC channel to get a resolution. Downloaded code, wiped out site-packages/django dir before running setup, took other suggestions. Nothing worked except removing the quotes as suggested on the django-users group. I am running Debian Etch final. Python 2.5 and Django 1.0.2, Apache2 with mod_python
AttributeError: 'str' object has no attribute '_default_manager
MOD_PYTHON ERROR
ProcessId: 2637
Interpreter: 'TS1.unassigned-domain'
ServerName: 'TS1.unassigned-domain'
DocumentRoot: '/var/www/'
URI: '/sipprovision/admin'
Location: '/sipprovision/'
Directory: None
Filename: '/var/www/sipprovision/admin'
PathInfo:
Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)
File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1229, in _process_target
result = _execute_target(config, req, object, arg)
File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1128, in _execute_target
result = object(arg)
File "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", line 228, in handler
return ModPythonHandler()(req)
File "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", line 201, in call
response = self.get_response(request)
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 67, in get_response
response = middleware_method(request)
File "/usr/lib/python2.5/site-packages/django/middleware/common.py", line 56, in process_request
if (not _is_valid_path(request.path_info) and
File "/usr/lib/python2.5/site-packages/django/middleware/common.py", line 142, in _is_valid_path
urlresolvers.resolve(path)
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 246, in resolve
return get_resolver(urlconf).resolve(path)
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 179, in resolve
for pattern in self.urlconf_module.urlpatterns:
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 198, in _get_urlconf_module
self._urlconf_module = import(self.urlconf_name, {}, {}, [])
File "/var/www/sipprovision/urls.py", line 2, in <module>
from extensions.models import Extension
File "/var/www/sipprovision/extensions/models.py", line 42, in <module>
class ExtensionForm(ModelForm):
File "/usr/lib/python2.5/site-packages/django/forms/models.py", line 195, in new
opts.exclude, formfield_callback)
File "/usr/lib/python2.5/site-packages/django/forms/models.py", line 162, in fields_for_model
formfield = formfield_callback(f)
File "/usr/lib/python2.5/site-packages/django/forms/models.py", line 177, in <lambda>
lambda f: f.formfield())
File "/usr/lib/python2.5/site-packages/django/db/models/fields/related.py", line 694, in formfield
'queryset': self.rel.to._default_manager.complex_filter(
AttributeError: 'str' object has no attribute '_default_manager'
from django.db import models
from sipconfig import *
from django.forms import ModelForm, fields, TextInput, IntegerField
# Create your models here.
class Plc(models.Model):
name=models.CharField(max_length=30)
ip_addr=models.IPAddressField()
ip_port=models.IntegerField(default=9600)
plc_net=models.IntegerField()
plc_node=models.IntegerField()
plc_unit=models.IntegerField()
def unicode(self):
return self.name
class Admin: pass
class VoipGateway(models.Model):
name=models.OneToOneField('sipconfig.station')
def unicode(self):
return self.name.dev_name
class Admin: pass
class Extension(models.Model):
PREFIX_CHOICE=(
('1','station'),
('9','lock'),
('8','voicemail'))
context=models.ForeignKey('sipconfig.station')
plc_sys=models.ForeignKey(Plc)
gateway=models.ForeignKey(VoipGateway)
word=models.IntegerField()
bit=models.IntegerField()
prefix=models.CharField(max_length=2,choices=PREFIX_CHOICE)
ph_number=models.CharField(max_length=8)
def unicode(self):
return self.context.dev_name +'-'+ self.ph_number
class Admin: pass
class ExtensionForm(ModelForm):
class Meta:
model = Extension
class ExtAddToContextForm(ModelForm):
word_increment=IntegerField(widget=TextInput,initial=0)
bit_increment=IntegerField(widget=TextInput,initial=0)
phone_increment = IntegerField(widget=TextInput,initial=0)
class Meta:
model = Extension
class PlcForm(ModelForm):
class Meta:
model=Plc
class VoipGatewayForm(ModelForm):
class Meta:
model=VoipGateway
from sipprovision.extensions.models import Plc,VoipGateway,Extension
from django.contrib import admin
class ExtensionAdmin(admin.ModelAdmin):
list_display=('context','plc_sys','gateway','word','bit','prefix','ph_number')
list_filter=('plc_sys','prefix')
class PlcAdmin(admin.ModelAdmin):
list_display=('name','ip_addr','ip_port','plc_node','plc_net','plc_unit')
admin.site.register(Plc,PlcAdmin)
admin.site.register(VoipGateway)
admin.site.register(Extension,ExtensionAdmin)
def formfield(self, kwargs):
defaults = {
'form_class': forms.ModelChoiceField,
'queryset': self.rel.to._default_manager.complex_filter(
self.rel.limit_choices_to),
'to_field_name': self.rel.field_name,
}
defaults.update(kwargs)
return super(ForeignKey, self).formfield(defaults)