Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Many to many related in admin
My model: class Person(models.Model): isMale = models.BooleanField(blank=True) wives = models.ManyToManyField('Person', related_name='husbands', blank=True) admin.py: class PersonAdminForm(forms.ModelForm): def clean(): super(PersonAdminForm, self).clean() return self.cleaned_data class PersonAdmin(admin.ModelAdmin): form = PersonAdminForm model = Person fields = ('isMale','wives',) admin.site.register(Person, PersonAdmin) On admin site the Many to many field is represented with ModelMultipleChoiceField() And now I want to have husbands field also with ModelMultipleChoiceField - finally I'd like to see only husbands or wives depends on sex of Person (I assume classic model of family - wive has to be a woman, husband - man) - If you want, I can change it into relatedA, relatedB, but I think that this is self descriptive) -
How to install psycopg2 for django
I have postgresql installed (with postgresql app). When I try "pip install psycopg2", i get "unable to execute gcc-4.2: No such file or directory. How to fix? -
Creating combinations from a tuple
I want to implement such a thing.... And in turn. I take the data from the database. From the database they come in the form of a tuple: [('test1', 'test12', 'test13', 'test14'), ('test21', 'test22', 'test23', 'test24'), ('test31', 'test32', 'test33', 'test34'), ('test41', 'test42', 'test43', 'test44'), ('test51', 'test52', 'test53', 'test54'), ('test61', 'test62', 'test63', 'test64'), ('test71', 'test72', 'test73', 'test74'), ('test81', 'test82', 'test83', 'test84'), ('test91', 'test92', 'test93', 'test94'), ('test11', 'test12', 'test13', 'test14')] And that's what I want: how to make combinations of these input... so the output I had a combination of 4 parameters (such as in example) and... 1) most importantly, new combinations,the values were always in its place, i.e. if in the original combinations the values were index [1], this means that in the new combination, it should also be [1]... 2) there are no duplicate combinations As example: I got tuple: [('test91', 'test92', 'test93', 'test94'), ('test11', 'test12', 'test13', 'test14')] And from this I got new combinations: [('test91', 'test12', 'test13', 'test14'), ('test11', 'test92', 'test93', 'test94')] Maybe it's possible to do using the method of pairwise or something else.... Help.... -
Parsley-validate resets the fields every time I close the form
So, I'm following this tutorial to make a form work within a Django class-based view, but I'm having some issues. The template: - base.html {% block form %} <!-- Trigger the modal with a button --> <button id="subscribe_btn" class="btn_sub_log"> <h2 class="top-menu sign-up">Sign up!</h2> </button> {% endblock %} <!-- Modal --> <div class="modal fade" id="subscribe_modal" 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> <h3 class="modal-title" id="sign-up">Register with Pin a Voyage</h3> </div> <div data-parsley-validate data-parsley-trigger="focusout" enctype="multipart/form-data" id="form-modal-body" class="modal-body"> <p>One fine body&hellip;</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> form.html {% extends 'blog/base.html' %} {% block form %} {% include 'blog/form_inner.html' %} {% endblock form %} and form_inner.html <div class="row"> <form data-parsley-validate id="user_form" action="{% url 'register' %}" method="post" enctype="multipart/form-data" data-parsley-trigger="focusout"> {% csrf_token %} {{ form.as_p }} <input type="submit" class="btn btn-info submit" name="register" value="Register" /> </form> And then, at the bottom of the page, the script {% block js %} <script> $('#subscribe_btn').click(function() { $('#form-modal-body').load('/register/', function () { $('#subscribe_modal').modal('toggle'); formAjaxSubmit('#form-modal-body form', '#subscribe_modal'); }); }); </script> {% endblock js %} The form does appear, and it works (if I write down all the data, the user gets registered); the parsley validation works too, but when … -
Django 1.9 URLField removing the necessary http:// prefix
I've seen a bunch of questions about this, but havent found an answer yet. This is my models: class UserProfile(models.Model): user = models.OneToOneField(User) . . . website = models.URLField(max_length=100, blank=True, null=True) and my forms.py: class UserProfileForm(forms.ModelForm): class Meta: model = UserProfile fields = ('website') def clean_website(self): website = self.cleaned_data['website'] if website and not website.startswith('http://'): website = 'http://' + website return website # def clean(self): # cleaned_data = self.cleaned_data # url = cleaned_data.get('url') # # if url and not url.startswith('http://'): # url = 'http://' + url # cleaned_data['url'] = url # return cleaned_data I've tried to clean the web address, but I the way django is set up I dont have an opportunity to get to the clean functions. How can I change Django to allow user the ability to not put in the http(s):// prefix? I don't want to initialize it with this type of code: url = forms.URLField(max_length=200, help_text="input page URL", initial='http://') I've seen this thread:django urlfield http prefix But admittedly am not sure where to put it to see if it even works. -
Facebook Messenger Bot publish error
My Facebook messenger bot was working perfectly, but as soon as i started the "Publish" process (making the bot available for everyone) my bot stopped responding. There is no error in my code or on the server, and the webhook is connected, and I tested my webhook connection and got a "{"success":true}" respond in terminal. Ever since i started the publish process I also started receiving these error messages from facebook: "Your Webhooks subscription for callback URL .... has not been accepting updates for at least 16 minutes" Somehow facebook managed to mess up my application, which was working perfectly fine, and know I cannot even get in contact with facebook, because there is no way to contact them. btw - my code is written in python and I have used Django -
Upload CSV file in django admin list view, replacing add object button
I want to replace the add object button in the listview of an admin page. The underlying idea is that an administrator can download data on all models in the db, use a tool to edit the data, and then reupload as a CSV file. In the list view I am struggling to override the form, as setting class SomeModelForm(forms.Form): csv_file = forms.FileField(required=False, label="please select a file") class SomeModel(admin.ModelAdmin): change_list_template = 'admin/my_app/somemodel/change_list.html' form = SomeModelForm other stuff This causes the error < class ‘my_model.admin.SomeModelAdmin'>: (admin.E016) The value of 'form' must inherit from 'BaseModelForm' I can surmise that this is due to the form overiding the form for an individual model, however I want to simply be able to upload a csv file on the listview for processing and generating new models from this. cheers -
Foreign key which related to other foreign key choice
I'm trying to make the following models in django: class Client(models.Model): client = models.CharField(max_length=200) loyal = models.BooleanField(default=False) class Contact(models.Model): first_name = models.CharField(max_length=200) last_name = models.CharField(max_length=200) client_id = models.ForeignKey(Client, on_delete=models.SET_NULL,null=True) class Activity(models.Model): title = models.CharField(max_length=30) text = models.CharField(max_length=1000) client_id = models.ForeignKey(Client, on_delete=models.PROTECT) contact_id = models.ForeignKey(Contact, on_delete=models.PROTECT,limit_choices_to={'id__in': client_id.contact_set.all().values('id').query}) What i want to achieve - when i creating an activity and choose client in it - i want that in contact field i have to choose only from the contacts which related to choosen client, because when i do: contact_id = models.ForeignKey(Contact, on_delete=models.PROTECT) Django allow me to choose from all the contacts. I want to limit somehow the list of contacts from i need to choose, i try this way: contact_id = models.ForeignKey(Contact, on_delete=models.PROTECT,limit_choices_to={'id__in': client_id.contact_set.all().values('id').query}) But i receive this error: AttributeError: 'ForeignKey' object has no attribute 'contact_set' How should i do it right? -
Complex DB query for ordering by two different properties in Django 1.6.7
I need to be able to order objects in Django 1.6.7 admin by two different rules. In words: There's a promotion codes system in place. Each promotion code is linked to a partner company (m2m) and usage instances of this code (m2m). The partner companies need to be ordered as follows: # 1st: The ones that have brought in the most clients in the last 6 months (highest count of promotion code usages) # 2nd: The ones that have brought in clients in the previous year (any number of promotion code usages) # 3rd: All the rest (No usages of promotion codes) In code: from django.db import models from django.utils import timezone class PromotionCode(models.Model): code = models.CharField(max_length, blahblahblah) class PromotionCodeUsage(models.Model): promotion_code = models.ForeignKey(PromotionCode, related_name='used') used_time = models.DateTimeField(default=timezone.now()) class Partner(models.Model): # tons of fields, name, etc... promotion_codes = models.ManyToManyField(PromotionCode, null=True, blank=True) I tried some ways, but haven't got the right results using the tools I have. I know how to do it using Django >=1.8 Case, When and other expressions like that, but unfortunately Django 1.6.7 doesn't have those. My first try. This works, but there is no way to concatenate the querysets (keeping the ordering), so I probably need to … -
Django, tutorial - error: No module named urls
Hi I am following the tutorial to make first web app by Django(link) But I was given this error: File "c:\Python27\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper fn(*args, **kwargs) File "c:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run self.check(display_num_errors=True) File "c:\Python27\lib\site-packages\django\core\management\base.py", line 374, in check include_deployment_checks=include_deployment_checks, File "c:\Python27\lib\site-packages\django\core\management\base.py", line 361, in _run_checks return checks.run_checks(**kwargs) File "c:\Python27\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks new_errors = check(app_configs=app_configs) File "c:\Python27\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config return check_resolver(resolver) File "c:\Python27\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver for pattern in resolver.url_patterns: File "c:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "c:\Python27\lib\site-packages\django\urls\resolvers.py", line 313, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "c:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "c:\Python27\lib\site-packages\django\urls\resolvers.py", line 306, in urlconf_module return import_module(self.urlconf_name) File "c:\Python27\lib\importlib\__init__.py", line 37, in import_module __import__(name) File "c:\Python27\Proj\mysite\mysite\urls.py", line 7, in <module> url(r'^polls/', include('polls.urls')) File "c:\Python27\lib\site-packages\django\conf\urls\__init__.py", line 50, in include urlconf_module = import_module(urlconf_module) File "c:\Python27\lib\importlib\__init__.py", line 37, in import_module __import__(name) ImportError: No module named urls I have read some answers here on SO, but they suggest that this error is caused by wrong version of framework, which is not my case. My version of python is 2.7 and Djanog 1.10.1 My urls.py from django.conf.urls import url, include from django.contrib import admin urlpatterns … -
Django Form Name as Attribute in HTML Template
I have an attribute of objects that can be rendered in html template like this : {{ mymodels.something }} In my case, i have forms containing an input field that has name similar with "something", so i want to run something like this in my template: {% for form in my_form %} {{ mymodels.form.name }} <!-- is same as mymodels.something --> {% endfor %} but it can't be rendered.. How can i do something like that? -
Django Admin: Numeric field filter
How to create filter for numeric data in Django Admin with range inputs? P.S. Found only this similar question, but here suggest only how to group by concrete ranges and last question activity was 2 years ago. Django Admin: How do I filter on an integer field for a specific range of values -
how to use modal in django template
I am using a Modal in django template. There are two buttons (Yes and No) and one cross button(window close). On clicking Yes button page is reloaded but I dont want to load that modal if I clicked Yes recently. If I click on No or cross then page is redirected to another page. Please tell me the logic of yes button. Thanks for help in advance. -
How to temporarily disable foreign key constraint in django
I have to update a record which have foreign key constraint. i have to assign 0 to the column which is defined as foreign key while updating django don't let me to update record. -
angularjs based free admin template [on hold]
I am building an Admin dashboard. I could find that there are tons of AngularJs based free admin templates. So not able to figure out the best, customizable and well documented template. So, is anyone has used such kind of the templates. Sharing some links for your reference. Blur Admin template Here are my exact requirements... Designed in Html5, css3 and bootstrap Developed using AngularJs 1.x Supports the documentation Free of cost -
Getting two model forms in a same form
I have two Models Post and Category. They have Many to Many relationship. Category has two mandatory fields category_name and category_slug. Similarly Post has title, body, status and publish. I have created two model forms, CategoryForm and PostForm. What I would like to do is have a form where user can choose the existing category if it already exists or add a new category if they want to and then fill out the post and submit. How can I achieve this? Something like this: Title: Body: publish: status: Category: choose from List of existing category or add category |category add button| |form submit button| Models.py class Category(models.Model): category_name = models.CharField(max_length=250, unique=True) category_slug = models.SlugField(max_length=250, unique=True) class Post(models.Model): STATUS_CHOICES = ( ('draft', 'Draft'), ('published', 'Published'), ) title = models.CharField(max_length=250) slug = models.SlugField(max_length=250, unique_for_date='publish') body = models.TextField() publish = models.DateTimeField(default=timezone.now) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft') categories = models.ManyToManyField(Category) def get_absolute_url(self): return reverse('posts:post_detail', args=[self.publish.year, self.publish.strftime('%m'), self.publish.strftime('%d'), self.slug]) Forms.py class PostForm(forms.ModelForm): class Meta: model = Post fields = [ 'title', 'body', 'publish', 'status', 'categories', ] class CategoryForm(forms.ModelForm): class Meta: model = Category fields = [ 'category_name', 'category_slug', ] Views.py def post_list(request): queryset = Post.objects.all() return render(request, 'posts/post_list.html', {'post_list': … -
Using regroup in Django template
I'm receiving a JSON object that contains many objects and lists of objects etc. In one of those lists is Year list like this: [{'Year': '2015', 'Status': 'NR', 'Month': 'Jan' {'Year': '2014', Status': '', 'Month': 'Jan'}, {'Year': '2015', 'Status': '',Month': 'Feb'}, {'Year': '2014', Status': '', 'Month': 'Feb'}, {'Year': '2015', 'Status': '', Month': 'Sep'}, {'Year': '2014', 'Status': 'OK', 'Month': 'Sep'}, {'Year': '2015', 'Status': '', 'Month': 'Oct'}, {'Year': '2014', 'Status': 'OK', 'Month': 'Oct'}] I need to group this list by Year and display months according to their year. For example: {"2015":[{"Month":"Jan", "Status":"NR"}, {"Month" : "Feb". "Status" :""}] Right now, the code I'm using doesn't work the way I want it to, instead it repeats the years according to the number of months: 2015 2014 2015 2014 2015 2014 2015 2014 This is the code: {% regroup x.LstPaymentBehaviour by Year as yearList %} {% for ym in yearList %} <tr> <td><strong>{{ ym.grouper }}</strong></td> </tr> {% endfor %} What am I missing? -
DRY way to call method if object does not exist, or flag set?
I have a Django database containing Paper objects, and a management command to populate the database. The management command iterates over a list of IDs and scrapes information about each one, and uses this information to populate the database. This command is run each week, and any new IDs are added to the database. If the object already exists, I don't scrape, which speeds things up hugely: try: paper = Paper.objects.get(id=id) except Paper.DoesNotExist: info = self._scrape_info(id) self._create_or_update_item(info, id) Now I want to set an UPDATE_ALL flag on the management command to update information about existing Paper objects, as well as just creating new ones. The problem is that it's not very DRY: try: paper = Paper.objects.get(id=id) if UPDATE_ALL: info = self._scrape_info(id) self._create_or_update_item(info, id) except Paper.DoesNotExist: info = self._scrape_info(id) self._create_or_update_item(info, id) How can I make this DRYer? Django obviously has the get_or_create method, which I'm using in _create_or_update_item. However, I only want to call self._scrape_info, as well as creating or updating the object. -
python Django connect button to new html
I want to link a submit button with a new response ( a new html). I am trying this but it does not work project/urls.py: from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^music/', include('music.urls')), ] app/urls.py: from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index,name='index'), ] models.py: from __future__ import unicode_literals from django.db import models # Create your models here. class Foo(models.Model): GENDER = ( ('B', 'black'), ('L', 'blue'), ('O', 'orange'), ('G', 'green'), ('Y', 'yellow'), ('R', 'red') ) number = models.CharField(max_length=150) color = models.CharField(max_length=1, choices=GENDER) views.py: from django.http import HttpResponse from django.http import HttpResponseRedirect from django.shortcuts import render from django.views.decorators.csrf import csrf_protect from .models import Foo def index(request): return render(request, 'music/index.html') def add_foo(request): if request.method == "POST": # Check if the form is submitted foo = Foo() # instantiate a new object Foo, don't forget you need to import it first foo.name = request.POST['name'] foo.gender = request.POST['gender'] foo.save() # You need to save the object, for it to be stored in the database #Now you can redirect to another page return HttpResponseRedirect('/success/') else: #The form wasn't submitted, show the template above return render(request, 'music/test1.html') index.html: <body> <form action="?" method="post"> … -
Django: Highlight current page in navbar
In my layout.html I have a navbar like this: <li class="dropdown"><a href="{% url 'index' %}" >Home </a></li> <li class="dropdown"><a href="{% url 'house_list' %}">Your houses</a></li> <li class="dropdown"><a href="{% url 'agency_list' %}">Agencies</a></li> <li class="dropdown"><a href="/admin">Admin</a></li> <li class="dropdown"><a href="{% url 'logout' %}"><i class="fa fa-lock"></i> Log ud</a></li> <li class="dropdown"><a href="{% url 'login' %}"><i class="fa fa-lock"></i> Log ind</a></li> I would like to highlight the current page in the navbar which is done by changing <li class="dropdown"> to <li class="dropdown active"> Is there a way for Django to insert active for the page the user is on? Any help is much appreciated! I'm using Django 1.9 and Python 3.5. -
How to create django view inside tests
I have some utility, which consist of middleware, and I need to test it. I need some view to emulate user request and I'm trying create view inside my test and use it in TestCase. But I don't know how to create it and assign to my test application. I have some settings for my test django application in run_tests.py file: from django.conf import settings, global_settings app_name = 'my_app' conf_kwargs = dict( DATABASES={ 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'test.db', 'TEST_NAME': 'test.db' } }, SITE_ID=1, MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES + ('my_app.middleware.MyMiddleware',), INSTALLED_APPS=( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', ) ) settings.configure(**conf_kwargs) from django.test.utils import get_runner runner = get_runner(settings)() failures = runner.run_tests((app_name,)) And then in the tests.py file I'm trying: from django.contrib.auth.models import User from django.http import HttpResponse from django.test import RequestFactory, TestCase def active_view(request): return HttpResponse('<h1>Test view has responsed<h1>') class ActiveUsersTest(TestCase): def setUp(self): self.factory = RequestFactory() self.user = User.objects.create_user(username='test', email='test@test.com', password='secret') def test_view(self): request = self.factory.get(active_view) request.user = self.user response = active_view(request) self.assertEqual(response.status_code, 200) Should I do separate test application for my goals? -
Error: django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet
I'm trying to write an importer for a csv file. Here is a minimal example csv_filepathname="/home/thomas/Downloads/zip.csv" your_djangoproject_home="~/Desktop/Projects/myproject/myproject/" import sys,os,csv sys.path.append(your_djangoproject_home) os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from django.db.models.fields.related import ManyToManyField from myapp.models import ZipCode,state dataReader = csv.reader(open(csv_filepathname), delimiter=',', quotechar='"') def import_SO(item, crit,val): debug = 1; obj_state=type(item).objects.filter(crit=val) <...some other stuff...> return for row in dataReader: st=state(statecode=row[2],statename=row[3]) import_SO(st,"statename",row[3]) And here is my model class state(models.Model): statecode = models.CharField(max_length=2, default='XX') statename = models.CharField(max_length=32, default='XXXXXXXXXXXXX') When i execute the code like it is, then i get the following error: File "load_data.py", line 101, in <module> import_SO(st,"statename",row[3]) # Objekt, Kriterium, zu vergleichender Wert File "load_data.py", line 68, in import_SO obj_state=type(item).objects.filter(crit=val)#crit=val) # suche object mit merkmal, hier statename File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py", line 127, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 679, in filter return self._filter_or_exclude(False, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/django/db/models/query.py", line 697, in _filter_or_exclude clone.query.add_q(Q(*args, **kwargs)) File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1310, in add_q clause, require_inner = self._add_q(where_part, self.used_aliases) File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1338, in _add_q allow_joins=allow_joins, split_subq=split_subq, File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1150, in build_filter lookups, parts, reffed_expression = self.solve_lookup_type(arg) File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1036, in solve_lookup_type _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta()) File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 1394, in names_to_path field_names = list(get_field_names_from_opts(opts)) File "/usr/lib/python2.7/dist-packages/django/db/models/sql/query.py", line 45, in get_field_names_from_opts for f in opts.get_fields() File … -
redis.exceptions.ConnectionError after approximately one day celery running
This is my full trace: Traceback (most recent call last): File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/celery/app/trace.py", line 283, in trace_task uuid, retval, SUCCESS, request=task_request, File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/celery/backends/base.py", line 256, in store_result request=request, **kwargs) File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/celery/backends/base.py", line 490, in _store_result self.set(self.get_key_for_task(task_id), self.encode(meta)) File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/celery/backends/redis.py", line 160, in set return self.ensure(self._set, (key, value), **retry_policy) File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/celery/backends/redis.py", line 149, in ensure **retry_policy File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/kombu/utils/__init__.py", line 243, in retry_over_time return fun(*args, **kwargs) File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/celery/backends/redis.py", line 169, in _set pipe.execute() File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/redis/client.py", line 2593, in execute return execute(conn, stack, raise_on_error) File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/redis/client.py", line 2447, in _execute_transaction connection.send_packed_command(all_cmds) File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/redis/connection.py", line 532, in send_packed_command self.connect() File "/home/propars/propars-v2-backend/venv/lib/python3.4/site-packages/redis/connection.py", line 436, in connect raise ConnectionError(self._error_message(e)) redis.exceptions.ConnectionError: Error 0 connecting to localhost:6379. Error. [2016-09-21 10:47:18,814: WARNING/Worker-747] Data collector is not contactable. This can be because of a network issue or because of the data collector being restarted. In the event that contact cannot be made after a period of time then please report this problem to New Relic support for further investigation. The error raised was ConnectionError(ProtocolError('Connection aborted.', BlockingIOError(11, 'Resource temporarily unavailable')),). I really searched for ConnectionError but there was no matching problem with mine. My platform is ubuntu 14.04. This is a part of my redis config. (I can share if you need … -
Continuous file corruptions multiple GIT repositories containing Django Projects
I have this very frustrating and weird problem regarding two Django Projects, which are in 2 separate GIT repositories. Let me define project 1 as A and project 2 as B. A has a homepage, with a connecting home.css file. I have checked the git repository for the contents of this file, overwriting my local copy, and copy pasted the raw contents of this file to home.css -> the homepage displays fine. Now, whenever I quit the Django processes and the virtual environment associated with it, and commit everything on git, and run the project again, the home.css file is suddenly corrupted. The page now looks like this: If I delete the home.css file from the directory and run the following commands: git fetch origin master git reset --hard FETCH_HEAD The project runs fine again (again the screenshot of the correct markup now): The really fun thing is, is that this happens with projects B AND A at the same time. So whenever A is screwed up, B is screwed up. And to add to my confusion: on another computer, with the same repositories, the files are also being changed leading to the corruption of the stylesheet. What is the … -
Django and dates in UTC
I use Django with USE_TZ set to True. I also set my TIME_ZONE. The thing is datetimes are stored in DB in UTC (-2 hours to my timezone). But when I print the datetime to template it's still in UTC. How do I automaticaly tell Django to print the datetimes in my local timezone (which should be default behavior). I use MySQL and datetime is saved as 2016-09-20 22:00:00 which is 2016-09-21 00:00:00 in my local timezone. Thanks.