не хочет отображаться fieldsets Django

393 просмотра
0
0 Комментариев

Имеется вот такая модель

class Forwarder(models.Model):
    name = models.CharField('Название',max_length=120, null=True, blank=True)
    link = models.CharField(max_length=120, null=True, blank=True)
    phone = models.CharField(max_length=120, null=True, blank=True)
    APPROVAL_CHOICES = (
        ('1', 'Viber'),
        ('2', 'Telegram'),
    )
    messanger = models.CharField('Мессенджер', max_length=100, default='Выберите мессенджер', blank=True, choices=APPROVAL_CHOICES)
    channel_id = models.CharField('ID канала', max_length=120, null=True, blank=True)
    users = models.ManyToManyField (ViberUser, blank=True, verbose_name='Viber пользователи')
 
    proj = models.ManyToManyField(Project,blank=True, related_name='tg_projects' ,verbose_name='Проекты')
    created_date = models.DateTimeField('Дата создания',auto_now_add=False, auto_now=False,null=True, blank=True)
    status = models.BooleanField(('Активирован'),default=True)
    comments = models.TextField('Комментарии',null=True, blank=True)

В admin.py файле пытаюсь сделать fieldsets

class ForwarderAdmin(admin.ModelAdmin):
    list_display_links = ('name',)
    list_display = ('status', 'icon', 'name', 'l', 'sitelink', 'created_date', 'd7', 'd30', 'd90')
    search_fields = ['name']
 
    fieldsets = (
    ('Информация о пересыльщике', {'fields': ('name', 'phone', 'messanger')}),
    ('Проект', {'fields': ('proj')}),
    ('Телеграм канал', {'fields': ('link', 'channel_id')}),
    ('Viber бот', {'fields': ('users', )}),
    ('Доп. поля', {'fields': ('created_date', 'status', 'comments')}),
    )

Получаю ошибку —

Traceback:
 
File "/home/worksection/env/lib/python3.6/site-packages/django/contrib/admin/options.py" in get_form
  668.             return modelform_factory(self.model, **defaults)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/forms/models.py" in modelform_factory
  549.     return type(form)(class_name, (form,), form_class_attrs)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/forms/models.py" in __new__
  266.                 raise FieldError(message)
 
During handling of the above exception (Unknown field(s) (r, p, o, j) specified for Forwarder), another exception occurred:
 
File "/home/worksection/env/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/contrib/admin/options.py" in wrapper
  574.                 return self.admin_site.admin_view(view)(*args, **kwargs)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/contrib/admin/options.py" in change_view
  1556.         return self.changeform_view(request, object_id, form_url, extra_context)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
  62.             return bound_func(*args, **kwargs)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func
  58.                 return func.__get__(self, type(self))(*args2, **kwargs2)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/contrib/admin/options.py" in changeform_view
  1450.             return self._changeform_view(request, object_id, form_url, extra_context)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/contrib/admin/options.py" in _changeform_view
  1479.         ModelForm = self.get_form(request, obj)
 
File "/home/worksection/env/lib/python3.6/site-packages/django/contrib/admin/options.py" in get_form
  672.                 % (e, self.__class__.__name__)
 
Exception Type: FieldError at /admin/bot/forwarder/7/change/
Exception Value: Unknown field(s) (r, p, o, j) specified for Forwarder. Check fields/fieldsets/exclude attributes of class ForwarderAdmin.

Если я уберу 2 строку из fieldsets

('Проект', {'fields': ('proj')}),

То все будет отлично отображатся и работать. Ошибки в кривом написании быть не может, т.к копировал названия из основной модели


Добавить комментарий

1 Ответы

Python Опубликовано 20.08.2019
0

Добавь запятую после ‘proj’, как-то так:

('Проект', {'fields': ('proj')}),
Добавить комментарий
Напишите свой ответ на данный вопрос.
Scroll Up

Подпишись на канал!

Новые видеоуроки, книги и полезные статьи для python программистов!