'Context' object has no attribute 'render_context' - django

I am running Django==3.2.12 and trying to generate a rendered tewmplate string. The following is the nuts and bolts of it....
I am recieving the error "'Context' object has no attribute 'render_context'" and can not make any sence of it.
It used to work fine, I am using django-mjml for this.
Code...
import uuid
from django.db import models
from django.template import Template, Context
from django.urls import reverse
class EmailTemplate(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, unique=True)
uuid = models.UUIDField(default = uuid.uuid4)
mjml_template = models.TextField(blank=True)
html_template = models.TextField(blank=True)
class Meta:
ordering = ['name', ]
verbose_name = 'Template'
verbose_name_plural = 'Templates'
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('pages:emailing', kwargs={'slug': self.slug, 'uuid': self.uuid})
def save(self, *args, **kwargs):
mjml_open = '{% load mjml %}{% mjml %}'
mjml_close = '{% endmjml %}'
verbatum_open = '{% verbatim %}{{'
verbatum_close = '}}{% endverbatim %}'
verbatum = self.mjml_template.replace('{{', verbatum_open)
verbatum = verbatum.replace('}}', verbatum_close)
verbatum = mjml_open + verbatum + mjml_close
template = Template(verbatum)
context = Context({})
passed = False
try:
self.html_template = template.render(context)
passed = True
except Exception as err:
self.html_template = str(err)
if passed:
image_categories = ImageCategory.objects.filter(templates=self)
for image_category in image_categories:
for image in image_category.get_images():
tag = '[~ ' + image.slug + ' ~]'
swap = self.html_template
swap = swap.replace(tag, image.image.url)
self.html_template = swap
resource_categories = ResourceCategory.objects.filter(templates=self)
for resource_category in resource_categories:
for resource in resource_category.get_resources():
tag = '[~ ' + resource.slug + ' ~]'
swap = self.html_template
swap = swap.replace(tag, resource.resource)
self.html_template = swap
super(EmailTemplate, self).save(*args, **kwargs)
Traceback....
Internal Server Error: /admin/emailing/emailtemplate/1/change/
Traceback (most recent call last):
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/contrib/admin/options.py", line 616, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/contrib/admin/sites.py", line 232, in inner
return view(request, *args, **kwargs)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/contrib/admin/options.py", line 1660, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/contrib/admin/options.py", line 1540, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/contrib/admin/options.py", line 1586, in _changeform_view
self.save_model(request, new_object, form, not add)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/contrib/admin/options.py", line 1099, in save_model
obj.save()
File "/Applications/MAMP/htdocs/mjml/emailing/models.py", line 42, in save
self.html_template = template.render(context)
File "/Users/sbrown/.local/share/virtualenvs/mjml-NNm5TF3H/lib/python3.9/site-packages/django/template/base.py", line 166, in render
with context.render_context.push_state(self):
AttributeError: 'Context' object has no attribute 'render_context'

Related

Django object of type 'method' has no len()

I just added pagination to a ListView in Django, but it is returning object of type 'method' has no len() error, even though I am overriding the get_queryset method and it is not returning anything different from the queryset.
The view causing the error looks like this:
class ProductList(ListView):
paginate_by = 10
model = Product
context_object_name = 'products'
template_name = 'catalog/product/product_list.html'
#method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
def queryset(self):
categories = Category.objects.filter(company=self.request.user.profile.company)
return Product.objects.filter(category__in=categories)
def get_context_data(self, **kwargs):
context = super(ProductList, self).get_context_data(**kwargs)
context['customers'] = Customer.objects.filter(company=self.request.user.profile.company)
context['categories'] = Category.objects.filter(company=self.request.user.profile.company)
return context
The full traceback:
Traceback (most recent call last):
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/views/generic/base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/home/ubuntu/dawipo/catalog/views.py", line 105, in dispatch
return super().dispatch(*args, **kwargs)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/views/generic/base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/views/generic/list.py", line 157, in get
context = self.get_context_data()
File "/home/ubuntu/dawipo/catalog/views.py", line 113, in get_context_data
context = super(ProductList, self).get_context_data(**kwargs)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/views/generic/list.py", line 119, in get_context_data
paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page_size)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/views/generic/list.py", line 69, in paginate_queryset
page = paginator.page(page_number)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/core/paginator.py", line 73, in page
number = self.validate_number(number)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/core/paginator.py", line 51, in validate_number
if number > self.num_pages:
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/core/paginator.py", line 100, in num_pages
if self.count == 0 and not self.allow_empty_first_page:
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/ubuntu/dawipoenv/lib/python3.6/site-packages/django/core/paginator.py", line 95, in count
return len(self.object_list)
Exception Type: TypeError at /catalog/list/
Exception Value: object of type 'method' has no len()
How am I supposed to paginate with an overriden queryset without it showing this error?
The method you override is get_queryset(…) [Django-doc], not queryset, queryset is an attribute, you can set a QuerySet object for that, but not use queryset as a method. You thus implement this as:
from django.contrib.auth.mixins import LoginRequiredMixin
class ProductList(LoginRequiredMixin, ListView):
paginate_by = 10
model = Product
context_object_name = 'products'
template_name = 'catalog/product/product_list.html'
# use get_queryset, not queryset
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs).filter(
category__company=self.request.user.profile.company
)
# …
Note: You can limit views to a class-based view to authenticated users with the
LoginRequiredMixin mixin [Django-doc].

Multiple objects returned in Django

So I have my code below, whenever I run it in admin and try to view that object returns and error:
Exception Type: MultipleObjectsReturned
Exception Value:
get() returned more than one c2 -- it returned 2!
How do I resolve this error?
models.py:
from django.db import models
import datetime
import pytz
from django.utils import timezone
class c1(models.Model):
name = models.CharField(max_length=30, default="Other")
def __str__(self):
return self.name
class c2(models.Model):
c1 = models.ForeignKey(c1, on_delete=models.CASCADE)
name = models.CharField(max_length=30, default="Other")
def __str__(self):
return self.name
class c3(models.Model):
c2 = models.ForeignKey(c2, on_delete=models.CASCADE)
name = models.CharField(max_length=30, default="Other")
def __str__(self):
return self.name
class Task_manager(models.Manager):
def create_Task(self, title):
Task1 = self.create(title=title)
return Task1
class Task(models.Model):
STATUS = (
('ONGOING', 'ONGOING'),
('COMPLETED','COMPLETED'),
)
search=models.CharField(max_length=300, choices=search_title, default="OTHER")
c1=models.ForeignKey(c1, on_delete=models.SET_NULL, null=True)
c2=models.ForeignKey(c2, on_delete=models.SET_NULL, null=True)
c3=models.ForeignKey(c3, on_delete=models.SET_NULL, null=True)
title=models.CharField(max_length=30,default="Other")
created=models.DateTimeField(default=timezone.now())
objects=Task_manager()
class Meta:
ordering = [ '-created']
def __str__(self):
return self.title
Here is my ModelAmdin class in admin.py
admin.py snippet:
class TaskAdmin(admin.ModelAdmin):
film_status.allow_tags = True'''
form=TaskForm
list_filter=('c1')
readonly_fields = ['score','score_fixed','deadline_fixed','created']
def change_view(self,request,object_id,extra_content=None):
return super(TaskAdmin,self).change_view(request,object_id)
admin.site.register(Task,TaskAdmin)
admin.site.register(c1)
admin.site.register(c2)
admin.site.register(c3)
You can also have a look at TaskForm class.
forms.py:
class TaskForm(forms.ModelForm):
class Meta:
model=Task
fields='__all__'
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['c1'].queryset = c1.objects.all()
self.fields['c2'].queryset = c2.objects.get()
self.fields['c3'].queryset = c3.objects.none()
Here is the full error for the code:
Traceback (most recent call last):
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\contrib\admin\options.py", line 607, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\contrib\admin\sites.py", line 231, in inner
return view(request, *args, **kwargs)
File "C:\My_Django_stuff\tada\todo\tasks\admin.py", line 64, in change_view
return super(TaskAdmin,self).change_view(request,object_id)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\contrib\admin\options.py", line 1641, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\contrib\admin\options.py", line 1522, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\contrib\admin\options.py", line 1582, in _changeform_view
form = ModelForm(instance=obj)
File "C:\My_Django_stuff\tada\todo\tasks\forms.py", line 14, in __init__
self.fields['c2'].queryset = c2.objects.get()
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\sarda\anaconda3\envs\myDjangoEnv\lib\site-packages\django\db\models\query.py", line 419, in get
raise self.model.MultipleObjectsReturned(
Exception Type: MultipleObjectsReturned at /admin/tasks/task/9/change/
Exception Value: get() returned more than one c2 -- it returned 2!
QuerySet.get() will raise an exception if the queryset does not contain exactly one object. Either an DoesNotExist or an MultipleObjectsReturned. This is by design.
You can handle this by using a try, except, of by calling another QuerySet method (.first() to get first object, for instance).

Django Pass parameters to Form, getting KeyError

I'm trying to pass two parameters to initialize my form, I have tried different ways to achieve this but I get the same error over an over, this is the error that I'm getting (Traceback):
Traceback (most recent call last):
File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\edit.py", line 168, in get
return super().get(request, *args, **kwargs)
File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\edit.py", line 133, in get
return self.render_to_response(self.get_context_data())
File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\edit.py", line 66, in get_context_data
kwargs['form'] = self.get_form()
File "C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\edit.py", line 33, in get_form
return form_class(**self.get_form_kwargs())
File "C:\Users\jorge.lopez\Documents\Personal\Carros\carros\AC\forms.py", line 100, in __init__
self.carro = kwargs.pop('carro')
Exception Type: KeyError at /payments/addtoexistingweek/1/2020-W07
Exception Value: 'carro'
Update
Exception Type: NoReverseMatch at /payments/addtoexistingweek/1/2020-W07
Exception Value: Reverse for 'pagoaexistente' with no arguments not found. 1 pattern(s) tried: ['payments/addtoexistingweek/(?P<carro>[0-9]+)/(?P<semana>[-a-zA-Z0-9_]+)$']
urls.py
path('payments/addtoexistingweek/<int:carro>/<slug:semana>',
views.AgregarPagoSemana.as_view(), name='pagoaexistente'),
views.py
Update
class AgregarPagoSemana(CreateView):
template_name = "AC/add_paymentexistingweek.html"
model = Pagos
form_class = AgregarPagoTransaccionExistente
def get_form_kwargs(self):
kwargs = super(AgregarPagoSemana, self).get_form_kwargs()
kwargs['carro'] = self.kwargs.get('carro')
kwargs['semana'] = self.kwargs.get('semana')
return kwargs
forms.py
class AgregarPagoTransaccionExistente(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.carro = kwargs.pop('carro')
self.semana = kwargs.pop('semana')
super(AgregarPagoTransaccionExistente, self).__init__(*args, **kwargs)
class Meta:
model = Pagos
fields = ('carro', 'pago', 'fecha', 'semana', 'renta')
widgets = {'fecha': forms.DateInput(attrs={'type': 'date'}),
'semana': forms.DateInput(attrs={'type': 'week'})
}
I don´t know if I'm understanding the error correctly and 'carro' is not getting the value.
You are passing the kwarg 'carro' to the view, but not to the form.
In your view, override the "get_form_kwargs" method and return the kwarg.
def get_form_kwargs(self):
kwargs = super(InternalResetPasswordView, self).get_form_kwargs()
kwargs['carro'] = self.kwargs.get('carro')
return kwargs

Django ImageField is unable to hande tif images

I am creating a django Project where I had Stored a Picture(Image) in database using ImageField as...
original_pic = models.ImageField()
Also, I want to Store an Image which will Contain the Same Picture(Image) as original_pic with Watermark in another ImageField as..
display_pic = models.ImageField(null=True, blank=True)
In short, I just want to Apply Algorithm on original_pic and save the result in watermark_pic using django models
Algorithm(Logic) for Applying Watermark to image is as follows...
def watermark_image_with_text(filename):
text = 'PicMesh'
color = 'blue'
fontfamily = 'arial.ttf'
image = Image.open(filename).convert('RGBA')
imageWatermark = Image.new('RGBA', image.size, (255, 255, 255, 0))
draw = ImageDraw.Draw(imageWatermark)
width, height = image.size
font = ImageFont.truetype(fontfamily, int(height / 20))
textWidth, textHeight = draw.textsize(text, font)
x = width / 5
y = height / 6
draw.text((x, y), text, color, font)
my_image = Image.alpha_composite(image, imageWatermark)
my_image.convert('RGB').save('D:\Github\PicMesh\media\water_'+
filename.name + '.png')
return 'D:\Github\PicMesh\media\water_'+filename.name + '.png'
My Models.py contains following Photo model that overwrites save method to store value in display_pic.
class Photo(models.Model):
format_of_tags = (
('PNG', 'PNG'),
('JPG', 'JPG'),
('JPEG', 'JPEG'),
('Exif', 'Exif'),
('TIF', 'TIF'),
('GIF', 'GIF'),
('WEBP', 'WEBP'),
('SVG', 'SVG'),
)
title = models.CharField(max_length=150)
format = models.CharField(max_length=20, choices=format_of_tags, blank=False)
tags = models.CharField(max_length=250)
original_pic = models.ImageField()
display_pic = models.ImageField(null=True, blank=True)
description = models.CharField(max_length=1000)
photographer = models.ForeignKey('Photographer', on_delete=models.CASCADE)
category = models.ForeignKey('Categories', on_delete=models.CASCADE, default=0)
# Overwrites save method and set value of display_pic by default
def save(self, *args, **kwargs):
if not self.pk:
rotate_img_name = watermark_image_with_text(self.original_pic)
self.display_pic = rotate_img_name
super().save(*args, **kwargs)
the Problem with the code is that it handles all formats of image perfectly for e.g- png,jpg,jpeg,etc but it is unable to handle image of format tif.
I got OSError when save() method is invoked
error trackback is as follows...
`Internal Server Error: /admin/home/photo/add/
Traceback (most recent call last):
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\contrib\admin\options.py", line 607, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\utils\decorators.py", line 140, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\contrib\admin\sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\contrib\admin\options.py", line 1647, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\utils\decorators.py", line 140, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\contrib\admin\options.py", line 1536, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\contrib\admin\options.py", line 1575, in _changeform_view
self.save_model(request, new_object, form, not add)
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django-2.1b1-py3.6.egg\django\contrib\admin\options.py", line 1094, in save_model
obj.save()
File "D:\Github\PicMesh\home\models.py", line 53, in save
rotate_img_name = watermark_image_with_text(self.original_pic)
File "D:\Github\PicMesh\home\models.py", line 16, in watermark_image_with_text
image = Image.open(filename).convert('RGBA')
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\Image.py", line 892, in convert
self.load()
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\TiffImagePlugin.py", line 1061, in load
return self._load_libtiff()
File "C:\Users\abx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\TiffImagePlugin.py", line 1153, in _load_libtiff
raise IOError(err)
OSError: -2
[29/Aug/2018 10:15:37] "POST /admin/home/photo/add/ HTTP/1.1" 500 132413`

Django Admin Console giving 'str' object has no attribute '__iter__' error

I am trying to make some changes in the fields using Djangos build in Admin console.It gives me 'str' object has no attribute 'iter' error exception when i try to change some fields in the models.These fields are Foreign Keys
PROJECT MODEL CAUSES ERROR WHEN I CHANGE THE MANAGER FIELD
class Project(models.Model):
"""Project Model.
"""
name = models.CharField(unique=True, max_length=255)
manager = models.ForeignKey('Employee', blank=True, null=True)
project = models.Manager()
class Employee(models.Model):
"""
Employee Model.
"""
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
email = models.CharField(
unique=True,
max_length=255,
blank=True,
null=True)
projects = models.ManyToManyField('Project', blank=True)
employee = models.Manager()
TRACEBACK
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _legacy_get_response
249. response = self._get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in wrapper
544. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
211. return view(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in change_view
1512. return self.changeform_view(request, object_id, form_url, extra_context)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapper
67. return bound_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in bound_func
63. return func.__get__(self, type(self))(*args2, **kwargs2)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in inner
185. return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in changeform_view
1451. change_message = self.construct_change_message(request, form, formsets, add)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in inner
185. return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in construct_change_message
942. elif form.changed_data:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in __get__
35. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/forms/forms.py" in changed_data
447. if field.has_changed(initial_value, data_value):
File "/usr/local/lib/python2.7/dist-packages/django/forms/fields.py" in has_changed
1075. initial = field.to_python(initial)
File "/usr/local/lib/python2.7/dist-packages/django/forms/fields.py" in to_python
424. return super(DateField, self).to_python(value)
File "/usr/local/lib/python2.7/dist-packages/django/forms/fields.py" in to_python
395. for format in self.input_formats:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in __wrapper__
112. return getattr(res, method_name)(*args, **kw)
Exception Type: AttributeError at /admin/login/project/2/change/
Exception Value: 'str' object has no attribute '__iter__'
admin.py file
from django.contrib import admin
from models import *
admin.site.register(Employee)
admin.site.register(Project)
I've had this problem myself. I upgraded from Django 1.10 to 1.10.2 and that seems to have fixed it for me. Good luck.