answerstu

Django - KeyError on formset form field

So I'm getting a KeyError, every time I try to submit a formset.I asked a similar question before here, and the solution seemed to work for a while, but now I get the above mentioned KeyError.Code and Trace below: Form: class CodingForm(forms.Form): NATIONAL = 0 REGIONAL = 1 LOCAL = 2 NA = 99 SCOPE_CHOICES = ( (NA, 'No Report'), (NATIONAL, 'National'), (REGIONAL, 'Regional'), (LOCAL, 'Local'), ) NO_VIO = 0 PROP_DMG = 1 INJ = 2 KILL = 3 PART_VIO = ( (NA, 'No Report'), (...Read more

django - DRF serializer do not return a value with extra_kwargs of write_only

I'm practicaly copying the exemple code from the documentation, but the password field, with "extra_kwargs = {'password': {'write_only': True}}" is not returned as validated data.this is the code:class UserProfileSerializer(serializers.ModelSerializer):class Meta: model = models.UserProfile fields = ('email', 'first_name', 'last_name', 'birthday', 'gender', 'telephone', 'password') extra_kwargs = {'password': {'write_only': True}}def create(self, validated_data): user = models.UserProfile( email=validated_data['email'], ...Read more

Monitoring tasks not working with django-celery, rabbitmq on virtualenv

I trying to make a work django with django-cellery, I created my project on virtualenv and I used template https://github.com/xenith/django-base-template and followings:Django==1.6.5celery==3.1.11django-celery==3.1.10My celery settings in settings/local.pyimport djcelerydjcelery.setup_loader()BROKER_URL = 'amqp://django:pas****@10.0.1.17:5672/myvhost'CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend'CELERY_ALWAYS_EAGER = TrueI have one Periodic Task "Update_All_Feeds"...Read more

django - Openshift wrapper vs. project repo

I've tried to find a concrete answer for this but failed. I'm rather new to openshift, django and git so I hope it's not too trivial and not a duplicate.The situation is as follows:1. I'm developing a Django based web application and source control it using git on a private bitbucket repo. I have my regular django application source tree as needed.2. I wish to deploy my app on openshift which comes with a different directory tree. I've been able to successfully run this quickstart:git://github.com/rancavil/django-openshift-quickstart.gitBasical...Read more

python 2.7 - How do I update Django on Openshift?

I'm learning to deploy Django on Openshift.Right now I have a python-2.7 cartridge up and running with Django 1.6The git repo cloned in the cartridge is,git://github.com/rancavil/django-openshift-quickstart.git (Github)How can I update the Django version of a running webapp?I've looked at this question that just explain about updating a cartridge, while I'm asking about updating the packages inside a cartridge while keeping the cartridge same as python-2.7....Read more

how to run celery with django on openshift 3

What is the easiest way to launch a celery beat and worker process in my django pod?I'm migrating my Openshift v2 Django app to Openshift v3. I'm using Pro subscription. I'm really a noob on Openshift v3 and docker and containers and kubernetes. I have used this tutorial https://blog.openshift.com/migrating-django-applications-openshift-3/ to migrate my app (which works pretty well).I'm now struggling on how to start celery. On Openshift 2 I just used an action hook post_start:source $OPENSHIFT_HOMEDIR/python/virtenv/bin/activatepython $OPENSHI...Read more

Django celery beat with Django as backend

I'm trying to set up Django-celery-beat in order to create periodic tasks.My configuration is as follows:from celery import Celeryimport osos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local')celery = Celery(broker="django-db")celery.autodiscover_tasks()CELERY_ACCEPT_CONTENT = ['json']CELERY_TASK_SERIALIZER = 'json'CELERY_RESULT_SERIALIZER = 'json'CELERY_TIMEZONE = 'UTC'CELERY_ENABLE_UTC = TrueCELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers.DatabaseScheduler'I'm trying to use Django as database and run both the beat se...Read more

python 3.x - only part of task executed when connection lost on redis using django celery

I have a django celery task that is only partly executing.I start up the app and the connection looks good: INFO/MainProcess] Connected to redis://elasticache.cache.amazonaws.com:6379/0 [2018-02-17 23:27:24,314: INFO/MainProcess] mingle: searching for neighbors [2018-02-17 23:27:25,339: INFO/MainProcess] mingle: all alone [2018-02-17 23:27:25,604: INFO/MainProcess] worker1@test_vmstracker_com ready.I initiate the process and the task is received an executed: [2018-02-17 23:27:49,810: INFO/MainProcess] Received task: tracking.tasks.escal...Read more

dynamic - Django : Formset as form field

one of the forms I need is a composite of simple fields (say "Department", "Building" and "RoomNumber"), and of dynamically generated pairs of fields (say "Name" and "Email"). Ideally, editing the contents of the simple fields and adding/removing dynamic field pairs would be done on a single form.Code-wise, I'm wondering if trying to embed a Formset (of a form with the two dynamic fields) as a field in an ordinary form is a sensible approach or if there's another best practice to achieve what I'd like to accomplish.Many thanks for any advice on...Read more

Create empty queryset by default in django form fields

I have this fields in form:city = forms.ModelChoiceField(label="city", queryset=MyCity.objects.all())district = forms.ModelChoiceField(label="district", queryset=MyDistrict.objects.all())area = forms.ModelChoiceField(label="area", queryset=MyArea.objects.all())district comes from click on city and area comes from click on area. With queryset=MyDistrict.objects.all() and queryset=MyArea.objects.all() form will be very heavy. How can I make querysets empty by default?Thanks in advance...Read more

custom user registration form in django

I've created custom user registration form for django, but it's not working :-( I've created LOGINSYS app to manipulate Users (Login, Profile page, Registration)My forms.py looks like this: #-*- coding:utf-8 -*- from django import forms from django.contrib.auth.models import User from django.contrib.auth.forms import UserCreationForm from datetime import date, timedelta class MyRegistrationForm(UserCreationForm): def get_image_path(self, filename): path = ''.join([date.today().strftime('../static/user_image/%...Read more

Django User Registration Form KeyError

When requesting a blank RegisterForm, I get a KeyError. I believe that when I click the link on the site, I submit a GET request to the register method and the form1 = RegisterForm() line fires. I believe there is something wrong with my RegisterForm class but I can't figure out what it is. I'm using the User model and UserCreationForm. Any help is greatly appreciated.KeyError at /profile/pm/register u'username'Traceback:File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py" in inner 39. response = get_resp...Read more

row wise duplicate data need to be eliminated(Rowspan) using Django Python

As i have a dictionary in python. Dictionary values look like.d= {'Report.thpl Team =FULL':{'cdp.c': 899, '_arp_fusen.c': 34, 'discovery.c': 34, 'subnet.c': 4}, 'P1.thpl Team = Over': {'discovery.c': 34, 'file23.c': 4, 'cdp/cdp.c': 937, '_fusen.c': 83}, 'P1_Report1.thpl': {'arp_fusen.c': 83, 'disynet.c': 34, 'routes.c': 2, 'routing.c': 937}}My table looks this|test | file_name |coverage |**********************************************************|Report.thpl Team =FULL | cdp.c | 899 ||Report.thpl T...Read more