0

I am receiving the following error as shown in the below traceback. I have included models.py from my project.

Thank you for the Help!

from django.db import models
from django.db.models.fields.related import ForeignKey


class DeviceType(models.Model):
    """Model representing a device type."""
    type_device_name = models.CharField(max_length=100)
    short_name_device= models.CharField(max_length=7, default='Maszyna')
    who_is_made = models.CharField(max_length=100)
    additional_notes = models.TextField(max_length=1000, help_text="Type all important information about.")

    def __str__(self):
        """String for representing the Model object."""
        return f'{self.short_name_device}'

class Device(models.Model):
    """Model representing a device."""
    type_name = models.ManyToManyField(DeviceType, help_text='Select a device type')
    device_id = models.DecimalField(max_digits=4, decimal_places=0)
    short_name_device_own = ForeignKey(DeviceType, related_name='device_type_device', on_delete=models.SET_NULL, null=True)
    prod_year = models.DateTimeField(auto_now=False, auto_now_add=False)
    worked_science = models.DateField(auto_now=False)

    @property
    def __str__(self):
        """String for representing the Model object."""
        return f'{self.short_name_device_own}, {self.device_id},'



Traceback:

File "/home/robert/.local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/home/robert/.local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/home/robert/.local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/robert/.local/lib/python3.6/site-packages/django/contrib/admin/options.py" in wrapper
  606.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/home/robert/.local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/robert/.local/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/home/robert/.local/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "/home/robert/.local/lib/python3.6/site-packages/django/contrib/admin/options.py" in add_view
  1634.         return self.changeform_view(request, None, form_url, extra_context)

File "/home/robert/.local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
  45.         return bound_method(*args, **kwargs)

File "/home/robert/.local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/robert/.local/lib/python3.6/site-packages/django/contrib/admin/options.py" in changeform_view
  1522.             return self._changeform_view(request, object_id, form_url, extra_context)

File "/home/robert/.local/lib/python3.6/site-packages/django/contrib/admin/options.py" in _changeform_view
  1565.                     self.log_addition(request, new_object, change_message)

File "/home/robert/.local/lib/python3.6/site-packages/django/contrib/admin/options.py" in log_addition
  810.             object_repr=str(object),

Exception Type: TypeError at /admin/dokumenty/device/add/
Exception Value: 'str' object is not callable
2
  • please add your urls.py and views.py as well. Commented Oct 6, 2019 at 11:56
  • 1
    @Shakil why did you ask that? The problem is clearly not there; the traceback show it is happening in the admin. Commented Oct 6, 2019 at 12:13

1 Answer 1

1

Remove @property decorator from __str__ method on Device model

Sign up to request clarification or add additional context in comments.

1 Comment

It's working! Thank you so much for your help (and correction).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.