Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Use NVL with string in Django?
On a Django app, I'm using cx_Oracle to display a roster of sports players: def get_players(self, sport_code='', term=0): """ :rtype: object """ con = cx_Oracle.Connection(settings.BANNER_CONNECTION_URL) cursor = con.cursor() query = 'select PREF_NAME, CLASS, ELIGIBLE_HOURS, CHECKED_IN, SEASONS_USED, MAJR1, NVL(MINR1, Null), CA_EMAIL, ID from swvsprt_web where ACTC = \'%s\' AND term = \'%s\' ORDER BY PREF_NAME' % ( sport_code, term) cursor.execute(query) players = cursor.fetchall() cursor.close() con.close() return players I want minor to just be blank if they don't have a minor NVL(MINR1, Null) But I can't quite get NVL to behave. "Null" makes it print the word "None." If I do NVL(MINR1, 0) it will display a 0, but if I try any of the following, they crash the site with a 500 error: NVL(MINR1, ) NVL(MINR1, '') NVL(MINR1, "") Can we use NVL to make it show null values as just nothing? -
AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2' with Python 2.7.6 on Ubuntu
I am having an issue that is eerily similar to this post on SO. I cannot use the answer there because I am on Ubuntu, and brew is for Mac. When I try to launch my Django server, (python manage.py runsslserver) I get the following error: AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2' I know I have OpenSSL installed for Python, as when I run import ssl and then print ssl.OPENSSL_VERSION in my Python environment, I get: OpenSSL 1.0.1f 6 Jan 2014 There must be something really simple I am missing here. Any help at all is appreciated. -
Translate country names to match browser language preference
I want Azerbaijan to show up in the browser as as Azerbaïdjan (French spelling). 1) I placed the django_countries dir (downloaded from https://pypi.python.org/pypi/django-countries) in my project root. 2) added "django_countries" to my INSTALLED_APPS 3) added "from django.utils.translation import ugettext_lazy as _ " in my app1/forms.py 4) changed the following (in the forms.ModelForm subclass): def clean_name(self): return self.cleaned_data['name'] to: def clean_name(self): return _(self.cleaned_data['name']) 5) changed the language preference in Chrome to French What am I missing? Thanks -
Bootstrap form in modal cannot resolve file
I want to link my deleteview URL to the 'yes' button on my modal, however, it is not deleting and in pycharm, it is showing up as: 'cannot resolve file'. I have checked my urls and view and they all seem to be correct. Any help is much appreciated. note: I am new to bootstrap {% for patient in all_patients %} <!-- Delete Patient --> <input type="hidden" name="patient_id" value="{{ patient.id }}" /> <button type="submit" class="btn btn-default btn-sm" data-toggle="modal" data-target="#{{patient.id}}"> <span class="glyphicon glyphicon-trash"></span> </button> <!-- Modal --> <div class="modal fade" id="{{patient.id}}" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Confirm delete</h4> </div> <div class="modal-body"> <p>Are you sure you want to delete {{ patient }}?</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">No</button> <form action="{% url 'patients:patient-delete' patient.id %}" method="post" style="display: inline;"> {% csrf_token %} <button type="button" class="btn btn-danger" data-dismiss="modal">Yes</button> </form> </div> </div> </div> </div> -
Cannot get the same digest (sha256) from same POST data
I am using Python requests package to send JSON data to an API. If the same data has been sent before the API discards it. The test uses a SHA256 digest of he data for comparison. Ideally I would obtain the digest in the server, but the digest keeps changing for the same data in different POST request. Now I do the hash in the client and send it with the data, but THERE MUST be a way to get constant data server side when the client POST the same JSON. The django request.body is bytes and unsuitable for hashing, it must be converted first to UTF-8, but even doing that leads to a different hash each time. Ideas? Thanks. -
Django integration with DynamoDB Database
I want to integrate DynamoDB as the database backend Django and make a little todo app as i made with mysql http://zainali95.pythonanywhere.com/todos .I did not find any good example for integrating using pynamodb or other library Thanks in advance ! -
Separate Datetime field to show Date and Time separate in HTML using Django
I am using Python 3.6 and Django as web framework I have to save datetime together in my database but show date and time separate field in HTML. Model Code: class date_time(models.Model): date = models.DateField(default=timezone.now) time = models.TimeField(default=timezone.now) Form Code: class date_time_Form(forms.ModelForm): class Meta: model = date_time fields = ('date', 'time',) widgets = { 'date': forms.TextInput(attrs={'class': 'form-control', 'type': 'date'}), 'time': forms.TextInput(attrs={'class': 'form-control', 'type': 'time'}), } labels = { 'date': 'Date', 'time': 'Time', } Currently, I am storing in separate field but I want to save in one field date+time. -
Production build for Django web app raising SuspiciousFileOperation when accessed
I am attempting to make a production build for my application however I am getting an error I do not really understand. The application runs, however an internal server error occurs every time it is accessed from localhost in a browser. This is the stack trace: [2017-09-01 17:34:07 +0100] [5301] [INFO] Starting gunicorn 19.7.1 [2017-09-01 17:34:07 +0100] [5301] [INFO] Listening at: http://127.0.0.1:8000 (5301) [2017-09-01 17:34:07 +0100] [5301] [INFO] Using worker: sync [2017-09-01 17:34:07 +0100] [5304] [INFO] Booting worker with pid: 5304 [2017-09-01 16:34:16 +0000] [5304] [ERROR] Error handling request / Traceback (most recent call last): File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle self.handle_request(listener, req, client, addr) File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request respiter = self.wsgi(environ, resp.start_response) File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/whitenoise/base.py", line 66, in __call__ return self.application(environ, start_response) File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 170, in __call__ response = self.get_response(request) File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 124, in get_response response = self._middleware_chain(request) File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 44, in inner response = response_for_exception(request, exc) File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 86, in response_for_exception response = get_exception_response(request, get_resolver(get_urlconf()), 400, exc) File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 116, in get_exception_response response = handle_uncaught_exception(request, resolver, sys.exc_info()) File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 143, in handle_uncaught_exception return callback(request, **param_dict) File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view response = view_func(request, *args, **kwargs) File "/Users/callum/Documents/Tutoring/Tutoring/venv/lib/python2.7/site-packages/django/views/defaults.py", line 74, in … -
django select widget works painfully slowly, but only on one project
I have a simple form and view that operate a universal Django object: from django.contrib.sessions.models import Session class TestForm(forms.Form): sessions = forms.ModelChoiceField(queryset=Session.objects.all()[:100]) class TestFormView(TemplateView): template_name = 'test_template.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['form'] = TestForm() return context And I render the field in a template simply like so: {{ form.sessions }} This very query behaves very differently in my different projects. It renders within a second on all of the projects except one, where it takes 30 seconds(!) to render. At the same time, if I create a <select> element explicitly everything renders fast again: <select> {% for s in form.fields.sessions.queryset.all %} <option value="{{ s.id }}">{{ s }}</option> {% endfor %} </select> I tried rendering Select widgets for other objects in the projects, and the result is the same: the {{ form.field }} syntax hangs the server if there are over 100 objects, and the explicit iteration works fast. So this project has an issue with Django widgets. What is even more weird is that the bug disappears when deployed to Heroku on the same Postgres version (9.6), same Python (3.5.0) and Django (1.11) versions. I tried completely reinstalling Virtualenv and all the modules from the requirements - this … -
When saving modelform, how to give a parent to the child?
In my model, the class Child(Parent) is inheriting the class Parent(models.Model). I've got a ChildForm(forms.Modelform) based on the Child model which allows to get some data from a form. then: if request.method == 'POST': # the form has been posted myform = ChildForm(request.POST) if myform.is_valid(): thechild = myform.save(commit=False) thechild.fieldA = A ... # adding some additional data to the object thechild.save() myform.save_m2m() # because there's an additional M2M table link to the Child. The question is: The parent already exists. I want to create a Child based on the parent (in a One to One relationship). How do I pass the Parent to the Child in the way that it knows who is its parent? -
Django Crispy Forms Add New Empty Form to ModelFormSet
What is the crispiest way to add a new, empty form to a modelformset with existing forms? forms.py: class MyForm(ModelForm): class Meta: model = MyModel fields = '__all__' MyFormSet = modelformset_factory(MyModel, extra=1, exclude=(), form=MyForm) class MyFormsetHelper(FormHelper): def __init__(self, *args, **kwargs): super(MyFormsetHelper, self).__init__(*args, **kwargs) self.form_method = 'post' self.template = 'bootstrap/table_inline_formset.html' self.add_input(Submit("submit", "Save")) template: {% extends "base.html" %} {% load staticfiles %} {% load crispy_forms_tags %} {% block stylesheets %} {{ block.super }} {% endblock stylesheets %} {% block content %} {% crispy formset helper %} {% endblock content %} I see that crispy forms has a way to add a generic button, but I don't see how to tie that to an action. I also don't know how crispy forms would create an empty form. Prior to discovering crispy forms, I was writing out all the template code and used something like the below to render the empty form. <div id="empty_form" style="display:none"> <table class='no_error'> <tr> <td>{{ modelformset.empty_form.Field1 }}</td> <td>{{ modelformset.empty_form.Field2 }}</td> <td>{{ modelformset.empty_form.Field3 }}</td> </tr> </table> </div> <input type="button" value="Add" id="add_more"> Thank you for any insight you all might have. -
Testing 'class Meta' in Django models
How can you test ordering, unique and unique_together in Django models? -
Passing a python's script object to Django's views.py
I'm trying to learn how to transfer my Highchart from a python script on to Django. I've been using this solution thread to get there (but in vain so far). I've got a python script called script.py that returns an object named chart_data. Now in Django, I'd like a function in my views.py to execute that script.py file, grab the chart_data object and allocate it to a new object called 'data'. My script.py file is stored in a directory called /scripts/ in my project root directory, and it contains its own __init__.py file. With the code below the server returns an error that states: global name 'chart_data' is not defined. Any explanations as to what I'm doing wrong here would be greatly appreciated. ### views.py from __future__ import unicode_literals import datetime import subprocess import scripts def plot(request, chartID = 'chart_ID', chart_type = 'line', chart_height = 500): raw = subprocess.Popen('~/scripts/script.py', shell=True) data = chart_data chart = {"renderTo": chartID, "type": chart_type, "height": chart_height,} title = {"text": 'my title here'} xAxis = {"title": {"text": 'xAxis name here'}, "categories": data['Freq_MHz']} yAxis = {"title": {"text": 'yAxis name here'}} series = [ {"name": 'series name here', "data": data['series name here']}, ] return render(request, '/chart.html', {'chartID': chartID, … -
django-allauth - getting user's FB picture to show up on his/her comments in post_detail template
I'm trying to get the user's Facebook picture to show up right next to his/her comments for a specific post. I have used django-allauth to allow users to login via Facebook. I'm not quite sure how this whole thing works, but I was able to get the user's First Name, Last Name & Email (From FB) to show up on each comment respectively. I can't seem to get the profile picture to work. Here's what I have so far models.py class UserProfile(models.Model): user = models.OneToOneField(User, related_name='profile') ... def profile_image_url(self): fb_uid = SocialAccount.objects.filter(user_id=self.user.id, provider='facebook') if len(fb_uid): fb_pic = "http://graph.facebook.com/{}/picture?width=1000&height=1000".format(fb_uid[0].uid) return fb_pic return "http://firstbagorganizer.com/image/m/user.png" User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0]) #Comment model class Comment(models.Model): ... post = models.ForeignKey(Post, related_name="comments") user = models.ForeignKey(User, related_name="usernamee") email = models.EmailField(null=True, blank=True) picture = models.ImageField(upload_to=None, null=True, blank=True) ... views.py @login_required def add_comment(request, slug): post = get_object_or_404(Post, slug=slug) if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) comment.post = post comment.user = request.user comment.email = request.user.email comment.picture = request.user.profile.profile_image_url comment.save() return redirect('blog:post_detail', slug=post.slug) else: form = CommentForm() template = "blog/post/add_comment.html" context = {'form': form} return render(request, template, context) template {% for comment in post.comments.all %} <img class="comment_image_css" src="{{ comment.picture }}"/> {{ comment.user.first_name }} {{ comment.user.last_name }} … -
Django deploy collectstatic error
I'm trying to deploy my Python Django project on server (useing Nginx). But when I collect statics python manage.py collectstatics I get the next error: Couldn't import Django. Are you sure it's installed and " ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment? But I have Django and "turned on" virtualenv -
Run task on Models datetime in django
Im working on a project and cant solve, probably, a simple issue. I have some datetime in a Model and I need to run some code when the current time reaches the Model datetime, so to say it is a sheduler with the provision from Models, also there is need to add some occurancies like every day, year, ... I wonder if there is a simple nice solution. Thanks forward.... -
Keyword 'undefined' is reserved. Appropriate loader to handle this file type
I am getting the following error while installing d3 packages and using npm start to run the angular page. Please help me Im a newbie here. I am using: npm install d3 --save npm install @types/d3 --save-dev ERROR in ./~/@ng-bootstrap/ng-bootstrap/typeahead/typeahead-window.js Module parse failed: C:\tpo\New\TPO\Client\test\node_modules\@ng- bootstrap\ng-bootstrap\typeahead\typeahead-window.js The keyword 'undefined' is reserved (53:91 ) You may need an appropriate loader to handle this file type. | }; | NgbTypeaheadWindow.prototype._activeChanged = function () { | this.activeChangeEvent.emit(this.activeIdx >= 0 ? this.id + '-' + this .activeIdx : undefined); | }; | return NgbTypeaheadWindow; @ ./~/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.module.js 4:0-56 8:0- 56 @ ./~/@ng-bootstrap/ng-bootstrap/index.js @ ./src/app/app.module.ts @ ./src/main.ts @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts ERROR in ./~/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.js Module parse failed: C:\tpo\New\TPO\Client\test\node_modules\@ng- bootstrap\ng-bootstrap\typeahead\typeahead.js The keyword 'undefined' is reserved (64:32) You may need an appropriate loader to handle this file type. | var userInput$ = _do.call(results$, function () { | if (!_this.editable) { | _this._onChange(undefined); | } | }); @ ./~/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.module.js 5:0-43 10:0- 43 @ ./~/@ng-bootstrap/ng-bootstrap/index.js @ ./src/app/app.module.ts @ ./src/main.ts @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts -
cant understand, how to make delete bottom?
Please help, i need to make button delete a 'cat' and just can't undestand how, django site not help =( MODELS from django.db import models class Cat(models.Model): class Meta(): db_table = "cat" paw = models.IntegerField(default=4) name = models.CharField(max_length=30, null=False, default='Cat') age = models.IntegerField(default=False, null=False) species = models.CharField(max_length=50, blank=True) hairiness = models.IntegerField(default=False, null=False) def __str__(self): return self.name URLS from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.home, name='home'), url(r'^new/$', views.new_cat, name='new_cat'), url(r'^edit/(?P<pk>[0-9]+)/$', views.cat_edit, name='cat_edit'), ] -
django-allauth twitch redirect_mismatch and a 404 page not found
I've been working the past 2 days on getting Twitch to be the sole social account for the website I'm building. I have ran into snags here and there though I've been able to find answers on google and on here. Sadly I have hit the limit and need to as as the Twitch setup seems not to be common and other than being told to go where to get an app key there isn't much documentation to be found. I'm able to get to the login page with the button clickable. My issue is the redirect_mismatch error. Inside setting up the Twitch clientid and secret key inside the admin panel there was no place to set a redirect url. After some digging I could the following: http://myapp.herokuapp.com/accounts/twitch/callback/ So naturally I went back into my twitch dev account and set the call back url. Waited for about 6 hours as I had other things to get done. Came back and twitch is still giving me the redirect_mismatch. Is there a different link for Twitch to use with django-allauth for their callback url? Lastly when I do get the information back from twitch stating its a wrong url redirect... ?error=redirect_mismatch&error_description=Parameter+redirect_uri+does+not+match+registered+URI&state=mhzOola6Em1m The … -
Django, convert data from JSON to DB or Ajax?
In my Django project I want to implement this Vue.js component, but I want data from JSON in this case: tasks( todo with description) will be saved at my Database. I try find a best solution. User create a new "todo" and then Django save it to DB. { "newTodoText": "", "todos": { "regular": [ "Do the dishes", "Take out the trash", "Mow the lawn" ], "priority": [], "done": [] } } https://codepen.io/supraniti/full/zogjGW What would be the best way to do this in Python? Can you give me idea, solutions? Thanks in advance. -
Upgrading to Django 1.11.4 ImportError
I'm attempting to upgrade Django from 1.10.7 to 1.11.4 with Python 2.7.11. I've run pip install Django -U and python -c "import django; print django.get_version()" confirms that Django 1.11.4 is installed. However, when I then go to run tests, I get ImportError: No module named notmigrations. Does anyone have any advice? Here is the full stack trace: Traceback (most recent call last): File "./manage.py", line 25, in <module> execute_from_command_line(sys.argv) File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line utility.execute() File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/commands/test.py", line 29, in run_from_argv super(Command, self).run_from_argv(argv) File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, **options) File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/commands/test.py", line 62, in handle failures = test_runner.run_tests(test_labels) File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/test/runner.py", line 601, in run_tests old_config = self.setup_databases() File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/test/runner.py", line 546, in setup_databases self.parallel, **kwargs File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/test/utils.py", line 187, in setup_databases serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True), File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 69, in create_test_db run_syncdb=True, File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/__init__.py", line 130, in call_command return command.execute(*args, **defaults) File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, **options) File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 83, in handle executor = MigrationExecutor(connection, self.migration_progress_callback) File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__ self.loader = MigrationLoader(self.connection) File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/loader.py", line 52, in __init__ self.build_graph() File "/home/vagrant/.virtualenvs/rhw/lib/python2.7/site-packages/django/db/migrations/loader.py", line 203, … -
Django Import by filename is not supported
I am new to django and I was trying to create a file upload page following Need a minimal Django file upload example instructions. However, I keep getting Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 1.8 Exception Type: ImportError Exception Value: Import by filename is not supported. Actual error seems to be happening here: C:\Users\306432857\AppData\Local\Continuum\Anaconda\lib\importlib__init__.py in import_module import(name) ... Thank you! -
Getting forms to display in HTML with Django
so I've gotten forms to display correctly before, I'm just a little lost as to why I am using certain words when doing so, and I'm wondering why I've used different words to get different forms to display. In this first example (colorist_form.html) I am using {{ form }} which does get the form to display {% extends "base.html" %} {% block content %} <div class="colorset-base"> <h2>Create new post</h2> <p class="hint">Add hex codes for each color you would like to include.</p> <form id="postForm" action="{% url 'colorsets:new_color' %}" method="POST"> {% csrf_token %} {{ form }} <button type="submit" class="submit btn btn-primary btn-large">Add Color Set</button> </form> </div> {% endblock %} However, in this example (widget_form.html) I am using the same {{ form }} but now the form does not display {% block content %} <div class="colorset-base"> <h2>Create new widget</h2> <form id="postForm" action="{% url 'adminpanel:create-widget' %}" method="POST"> {% csrf_token %} {{ form }} <button type="submit" class="submit btn btn-primary btn-large">Add Widget</button> </form> </div> {% endblock %} Also in my register.html I am using {{ user_form }} which does get the form to display. {% extends "base.html" %} {% block content %} <div class="form-base"> {% if registered %} <h1>Thank you for registering!</h1> {% else %} <h2>Register</h2> … -
Django prefetch_related on __str__() method
My models: class B(models.Model): label = models.CharField() class A(models.Model): b = models.OneToOneField(B, null=True, blank=True, on_delete=models.PROTECT) def __str__(self): return u'[{}] Event:'.format(self.b.label) Now, looking queries done during a request with django debug toolbar, i noted that many queries are executed 200+ times. I understand that I will solve using prefetch_related, but where do I have to put it when the lookup is done inside the str method? -
Python List Bug in a for loop
I'm not sure how to describe the issue but I'll try it. Background info I have in my Django web application a function where the user can import other users. The user can via drag and drop import a .csv file which gets converted to a JSON 2D Array (with Papaparse JS) In the view, I loop through the elements in the 2D array and create an "Importuser" which contains some properties like "firstname", "lastname", email and so on. class Importuser: firstname = None lastname = None email = None import_errors = [] def __init__(self, fn, ln, e): self.firstname = fn self.lastname = ln self.email = e class Importerror: message = None type = None def __init__(self, m, t): self.message = m self.type = t In the for-loop, I also validate the email-address, so that there are no doubled users. data = jsonpickle.decode(method.POST["users"]) users = [] for tempuser in data: u = validate(Importuser(tempuser[0], tempuser[1], tempuser[2]) users.append(u) In the validate function I check if there any user with the same email def validate(user : Importuser): user_from_db = User.objects.filter(email=user.email) if user_from_db: user.import_errors.append(Importerror("The user exists already!", "doubleuser")) return user Issue After the for-loop finished all user have the same error but not when …