SHARE
TWEET

Untitled

a guest Aug 12th, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Category(models.Model):
  2.     name = models.CharField(max_length=200, unique=True)
  3.     slug = models.SlugField(blank=True, editable=False)
  4.     image = models.ImageField(upload_to='images', blank=True)
  5.  
  6.     def __str__(self):
  7.         """
  8.             Field to show in the related models admin site.
  9.         """
  10.         return self.name
  11.  
  12.     class Meta:
  13.         # order of drop-down list items
  14.         ordering = ('name',)
  15.  
  16.         # plural form in admin view
  17.         verbose_name_plural = 'categories'
  18.  
  19.     def save(self, *args, **kwargs):
  20.         """
  21.             Save slug when saving model.
  22.             Slug saved only if not existant, to avoid duplicity of urls.
  23.         """
  24.         if not self.id:
  25.             # new object to create
  26.             self.slug = slugify(self.name)[:50]
  27.  
  28.         super().save(*args, **kwargs)
  29.    
  30. Internal Server Error: /admin/quotes/category/8/change/
  31. Traceback (most recent call last):
  32.   File "/usr/lib/python3.6/site-packages/django/core/handlers/exception.py", line 39, in inner
  33.     response = get_response(request)
  34.   File "/usr/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
  35.     response = self.process_exception_by_middleware(e, request)
  36.   File "/usr/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
  37.     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  38.   File "/usr/lib/python3.6/site-packages/django/contrib/admin/options.py", line 544, in wrapper
  39.     return self.admin_site.admin_view(view)(*args, **kwargs)
  40.   File "/usr/lib/python3.6/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
  41.     response = view_func(request, *args, **kwargs)
  42.   File "/usr/lib/python3.6/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
  43.     response = view_func(request, *args, **kwargs)
  44.   File "/usr/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 211, in inner
  45.     return view(request, *args, **kwargs)
  46.   File "/usr/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1512, in change_view
  47.     return self.changeform_view(request, object_id, form_url, extra_context)
  48.   File "/usr/lib/python3.6/site-packages/django/utils/decorators.py", line 67, in _wrapper
  49.     return bound_func(*args, **kwargs)
  50.   File "/usr/lib/python3.6/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
  51.     response = view_func(request, *args, **kwargs)
  52.   File "/usr/lib/python3.6/site-packages/django/utils/decorators.py", line 63, in bound_func
  53.     return func.__get__(self, type(self))(*args2, **kwargs2)
  54.   File "/usr/lib/python3.6/contextlib.py", line 53, in inner
  55.     return func(*args, **kwds)
  56.   File "/usr/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1449, in changeform_view
  57.     self.save_model(request, new_object, form, not add)
  58.   File "/usr/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1007, in save_model
  59.     obj.save()
  60.   File "/home/hakim/project/app/models.py", line 103, in save
  61.     super().save(*args, **kwargs)
  62.   File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 796, in save
  63.     force_update=force_update, update_fields=update_fields)
  64.   File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 824, in save_base
  65.     updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  66.   File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 886, in _save_table
  67.     for f in non_pks]
  68.   File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 886, in <listcomp>
  69.     for f in non_pks]
  70.   File "/usr/lib/python3.6/site-packages/django/db/models/fields/files.py", line 292, in pre_save
  71.     file.save(file.name, file, save=False)
  72.   File "/usr/lib/python3.6/site-packages/django/db/models/fields/files.py", line 91, in save
  73.     self.name = self.storage.save(name, content, max_length=self.field.max_length)
  74.   File "/usr/lib/python3.6/site-packages/django/core/files/storage.py", line 53, in save
  75.     name = self.get_available_name(name, max_length=max_length)
  76.   File "/usr/lib/python3.6/site-packages/django/core/files/storage.py", line 77, in get_available_name
  77.     while self.exists(name) or (max_length and len(name) > max_length):
  78.   File "/usr/lib/python3.6/site-packages/django/core/files/storage.py", line 394, in exists
  79.     return os.path.exists(self.path(name))
  80.   File "/usr/lib/python3.6/site-packages/django/core/files/storage.py", line 407, in path
  81.     return safe_join(self.location, name)
  82.   File "/usr/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
  83.     res = instance.__dict__[self.name] = self.func(instance)
  84.   File "/usr/lib/python3.6/site-packages/django/core/files/storage.py", line 283, in location
  85.     return abspathu(self.base_location)
  86.   File "/usr/lib/python3.6/posixpath.py", line 369, in abspath
  87.     path = os.fspath(path)
  88. TypeError: expected str, bytes or os.PathLike object, not tuple
RAW Paste Data
Top