Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type object 'TransitionApproval' has no attribute '_mptt_meta' #196

Open
ahmedalrifai opened this issue Oct 25, 2021 · 1 comment
Open

Comments

@ahmedalrifai
Copy link

Hello to all 👋, great package u have here hope us fix this problem soon

When i try to access TransitionApproval add page in admin it tells me that there is no _mptt_meta atrr

I think to fix it u must let TransitionApproval inherit from mptt.models.MPTTModel

This is my Tracback

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/river/transitionapproval/add/

Django Version: 2.2.17
Python Version: 3.8.10
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'corsheaders',
 'rest_framework',
 'django_filters',
 'drf_spectacular',
 'django_jsonfield_backport',
 'django_celery_results',
 'django_celery_beat',
 'channels',
 'behave_django',
 'river',
 'mptt',
 'core',
 'users',
 'chat',
 'task_management']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\core\handlers\base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\core\handlers\base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in wrapper
  606.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in add_view
  1645.         return self.changeform_view(request, None, form_url, extra_context)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\utils\decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in changeform_view
  1529.             return self._changeform_view(request, object_id, form_url, extra_context)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in _changeform_view
  1562.         ModelForm = self.get_form(request, obj, change=not add)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in get_form
  669.             fields = flatten_fieldsets(self.get_fieldsets(request, obj))

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in get_fieldsets
  330.         return [(None, {'fields': self.get_fields(request, obj)})]

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in get_fields
  321.         form = self._get_form_for_get_fields(request, obj)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in _get_form_for_get_fields
  659.         return self.get_form(request, obj, fields=None)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in get_form
  705.             return modelform_factory(self.model, **defaults)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\forms\models.py" in modelform_factory
  551.     return type(form)(class_name, (form,), form_class_attrs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\forms\models.py" in __new__
  251.             fields = fields_for_model(

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\forms\models.py" in fields_for_model
  176.             formfield = formfield_callback(f, **kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in formfield_for_dbfield
  156.                 formfield = self.formfield_for_foreignkey(db_field, request, **kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\contrib\admin\options.py" in formfield_for_foreignkey
  243.         return db_field.formfield(**kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\mptt\fields.py" in formfield
  34.         return super(TreeOneToOneField, self).formfield(**kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\db\models\fields\related.py" in formfield
  1022.         return super().formfield(**kwargs)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\db\models\fields\related.py" in formfield
  952.         return super().formfield(**{

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\db\models\fields\related.py" in formfield
  419.         return super().formfield(**defaults)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\django\db\models\fields\__init__.py" in formfield
  897.         return form_class(**defaults)

File "C:\Users\Ahmed Alrifai\Projects\portfoliopro\backend\venv\lib\site-packages\mptt\forms.py" in __init__
  29.             mptt_opts = queryset.model._mptt_meta

Exception Type: AttributeError at /admin/river/transitionapproval/add/
Exception Value: type object 'TransitionApproval' has no attribute '_mptt_meta'

@AngelLiang
Copy link
Contributor

hi, I have the same problem, and I have solved as follow:

create TransitionApprovalForm to exclude previous field and add to TransitionApprovalAdmin

from django.contrib import admin
from django import forms
from river.models.transitionapproval import TransitionApproval

class TransitionApprovalForm(forms.ModelForm):
    class Meta:
        model = TransitionApproval
        exclude = ('previous',)

class TransitionApprovalAdmin(admin.ModelAdmin):
    ...
    form = TransitionApprovalForm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants