from django.db import models
class Item(models.Model):
name = models.CharField(max_length=250)
description = models.TextField
class Meta:
ordering = ['name']
def __unicode__(self):
return self.name
@models.permalink
def get_absolute_url(self):
return ('item_detail', None, {'object_id': self.id})
class Photo(models.Model):
item = models.ForeignKey(Item)
title = models.CharField(max_length=100)
image = models.ImageField(upload_to='photos')
caption = models.CharField(max_length=250, blank=True)
class Meta:
ordering = ['title']
def __unicode__(self):
return self.title
@models.permalink
def get_absolute_url(self):
return ('photo_detail', None, {'object_id': self.id})
class PhotoInline(admin.StackedInline):
model = Photo
class ItemAdmin(admin.ModelAdmin):
inlines = [PhotoInline]
admin.site.register(Item, ItemAdmin)
admin.site.register(Photo)
И получаю такие вот ошибки в консоли
File "./manage.py", line 11, in <module> execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 362, in execute_manager utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 303, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 195, in run_from_argv self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 221, in execute self.validate()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 249, in validate num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py", line 28, in get_validation_errors for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 131, in get_app_errors self._populate()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 58, in _populate self.load_app(app_name, True)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 74, in load_app models = import_module('.models', app_name)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module __import__(name)
File "/home/kirillka/django/proj/mysite/../mysite/blog/models.py", line 15, in <module> admin.site.register(BlogPost, BlogPostAdmin)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py", line 90, in register validate(admin_class, model)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.py", line 22, in validate models.get_apps()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 100, in get_apps self._populate()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 58, in _populate self.load_app(app_name, True)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 74, in load_app models = import_module('.models', app_name)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module __import__(name)
File "/home/kirillka/django/proj/mysite/../mysite/gallery/models.py", line 3, in <module> class Item(models.Model):
File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 92, in __new__ new_class.add_to_class(obj_name, obj)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/base.py", line 213, in add_to_class value.contribute_to_class(cls, name)
TypeError: Error when calling the metaclass bases
unbound method contribute_to_class() must be called with TextField instance as first argument (got ModelBase instance instead)