I am sorry, it was up all night working on this, and I was tired, and
honestly didn't want to piss anyone off or offend anyone.

...here is the actual code in question:

Snippet from models.py:
class DisneySpotType(models.Model):
    name = models.CharField(max_length=128, primary_key=True)

    def __unicode__(self):
        return self.name

    class Meta:
        ordering = ['name']
        verbose_name = 'Disney Spot Type'
        verbose_name_plural = 'Disney Spot Types'

class DisneySpot(models.Model):
    PARK_CHOICES = (
        ('MK','Magic Kingdom'),
        ('E','Epcot'),
        ('HS','Holywood Studios'),
        ('AK','Animal Kingdom'),
        ('O','Other'),
    )
    name = models.CharField(max_length=256)
    description = models.TextField(DisneySpotType)
    park = models.CharField(max_length=2, choices=PARK_CHOICES)
    types = models.ManyToManyField(DisneySpotType)
    location = models.ForeignKey(DisneyLocation)
    altitude = models.DecimalField(max_digits=30,decimal_places=15)
    horizontal_accuracy = models.DecimalField
(max_digits=30,decimal_places=15)
    vertical_accuracy = models.DecimalField
(max_digits=30,decimal_places=15)
    publish_date = models.DateTimeField('date published')
    last_update_date = models.DateTimeField('date last updated')

    def __unicode__(self):
        return self.name

    class Meta:
        ordering = ['park','name','description','publish_date']
        verbose_name = 'Disney Spot'
        verbose_name_plural = 'Disney Spots'
        get_latest_by = "publish_date"


The full admin.py:
from disney.models import *

from django.contrib import admin
from django.contrib.auth.models import User

class DisneySpotTypeAdmin(admin.ModelAdmin):
    list_display = ('name',)
    fields = ('name',)

class DisneySpotTagAdminInline(admin.StackedInline):
    model = DisneySpotTag
    verbose_name = 'Tag'
    verbose_name_plural = 'Tags'

class DisneySpotTagAdmin(admin.ModelAdmin):
    list_display = ('tag','disney_spot')

class DisneySpotAdmin(admin.ModelAdmin):
    list_display =
('name','park','description','publish_date','last_update_date')
    list_filter = ('park','types',)
    filter_horizontal = ('types',)
    inlines = [
        DisneySpotTagAdminInline,
    ]

class DisneyLocationAdmin(admin.ModelAdmin):
    list_display = ('latitude','longitude',)

admin.site.register(DisneySpot,DisneySpotAdmin)
admin.site.register(DisneySpotType,DisneySpotTypeAdmin)
admin.site.register(DisneySpotTag,DisneySpotTagAdmin)
admin.site.register(DisneyLocation,DisneyLocationAdmin)
admin.site.register(DisneyPhoto)


Full trace:
Traceback (most recent call last):

 File "/var/lib/python-support/python2.5/django/core/handlers/
base.py", line 86, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/var/lib/python-support/python2.5/django/contrib/admin/
sites.py", line 158, in root
   return self.model_page(request, *url.split('/', 2))

 File "/var/lib/python-support/python2.5/django/views/decorators/
cache.py", line 44, in _wrapped_view_func
   response = view_func(request, *args, **kwargs)

 File "/var/lib/python-support/python2.5/django/contrib/admin/
sites.py", line 177, in model_page
   return admin_obj(request, rest_of_url)

 File "/var/lib/python-support/python2.5/django/contrib/admin/
options.py", line 191, in __call__
   return self.add_view(request)

 File "/var/lib/python-support/python2.5/django/db/transaction.py",
line 238, in _commit_on_success
   res = func(*args, **kw)

 File "/var/lib/python-support/python2.5/django/contrib/admin/
options.py", line 486, in add_view
   ModelForm = self.get_form(request)

 File "/var/lib/python-support/python2.5/django/contrib/admin/
options.py", line 277, in get_form
   return modelform_factory(self.model, **defaults)

 File "/var/lib/python-support/python2.5/django/forms/models.py", line
318, in modelform_factory
   'formfield_callback': formfield_callback})

 File "/var/lib/python-support/python2.5/django/forms/models.py", line
180, in __new__
   opts.exclude, formfield_callback)

 File "/var/lib/python-support/python2.5/django/forms/models.py", line
147, in fields_for_model
   formfield = formfield_callback(f)

 File "/var/lib/python-support/python2.5/django/contrib/admin/
options.py", line 86, in formfield_for_dbfield
   return db_field.formfield(**kwargs)

 File "/var/lib/python-support/python2.5/django/db/models/fields/
__init__.py", line 789, in formfield
   return super(TextField, self).formfield(**defaults)

 File "/var/lib/python-support/python2.5/django/db/models/fields/
__init__.py", line 306, in formfield
   defaults = {'required': not self.blank, 'label': capfirst
(self.verbose_name), 'help_text': self.help_text}

 File "/var/lib/python-support/python2.5/django/utils/functional.py",
line 251, in wrapper
   return func(*args, **kwargs)

 File "/var/lib/python-support/python2.5/django/utils/text.py", line
9, in <lambda>
   capfirst = lambda x: x and force_unicode(x)[0].upper() +
force_unicode(x)[1:]

 File "/var/lib/python-support/python2.5/django/utils/encoding.py",
line 49, in force_unicode
   s = unicode(s)

TypeError: unbound method __unicode__() must be called with
DisneySpotType instance as first argument (got nothing instead)

On Nov 11, 8:50 am, Karen Tracey <kmtra...@gmail.com> wrote:
> On Wed, Nov 11, 2009 at 7:06 AM, django_fo...@codechimp.net <
>
>
>
> codech...@gmail.com> wrote:
>
> > I have a class, A, that has a ManyToMany reference to another class, B
> > like so:
>
> >    class B(models.Model):
> >        name = models.CharField()
>
> >        def __unicode__(self)
> >            return self.name
>
> >    class A(models.Model):
> >        name = models.CharField()
> >        bees = models.ManyToManyField(B)
>
> >        def __unicode__(self)
> >            return self.name
>
> > And an ModelAdmin setup like:
> >    class AAdmin(admin.ModelAdmin):
> >        filter_horizontal = ('bees')
>
> > Everything works perfectly fine when I run this on my local test
> > server.
>
> The code above can't possibly be working fine.  It has several errors --
> missing colons, missing parameter on the CharFields, missing comma in the
> filter_horizontal specification.  When trimming down from your real code
> it's important to verify before posting that what you are posting actually
> works and actually still exhibits the problem you are posting about.  The
> likelihood of someone taking what you have posted and correcting the errors
> while still introducing whatever problem is causing the exception you are
> seeing is slim.
>
> However, when I move the code "as-is" to my server and I try> to add a new 
> 'A', I get the following error:
> >    TypeError: unbound method __unicode__() must be called with B
> > instance as first argument (got nothing instead)
>
> Also, please include the complete traceback, not just the error message.  In
> the absence of the actual code you are using the traceback at least might
> provide enough clues for someone to point in a direction of what the error
> might be.  As it is all I can tell you is that the error message indicates
> some code is apparently attempting to apply unicode() to the B class instead
> of an instance of the B class.  The traceback would show exactly what and
> where that code is.
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to