Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Best Practice for running Machine Learning Model
I am creating a bus arrival prediction app with the following architecture !Web App Architecture I will be pulling current data from weather, event APIs etc, as well as taking user input through react interface to choose a particular bus stop. I would then like to send this information to be run on the trained models I've created. I've previously done similar in a flask app sending the data to the backend using Ajax and then loading the appropriate pickle file with the data and returning the result. I'm wondering is there any better way of doing this, given the proposed architecture. I'm particularly interested in how this might work with the use of Apollo GraphQL. I've read some research on security risks using pickle, as well as options to run the models in the front end using TensorFlowJS. It would be great to generate a discussing here on best practices. Please keep in mind I am new to web development and so the more complete information you can share the better. -
graphql schema field need to return one of defined type
i got this problem. My Collection model consists of a multiple item and content_type. This content_type can be either Artist or Album. So i put my schema like following. Now i want to assign type. I tried union type but no luck. union CollectionItemsType = Album | Artist type Collection { id: ID! title: String! subtitle: String cover: String! thumb: String content_type: String items(first: Int, skip: Int): [CollectionItemsType] } PS: i am using this on Django with Ariadne graphql -
Django: Dots in slug don't work in DetailView
I'm modelling genome assemblies whose names often contain a dot (.) I wrote a DetailView which works for names without dots but noth names with dots. I get this error: 404 - Using the URLconf defined in genomeDBmanager.urls, Django tried these URL patterns, in this order: ... My model: class Assembly(models.Model): ... identifier = models.SlugField('unique identifier', max_length=50, unique=True) ... My view.py: class AssemblyDetailView(DetailView): slug_field = 'identifier' template_name = 'overview/assembly.html' model = Assembly context_object_name = 'assembly' My overview/urls.py: app_name = 'overview' urlpatterns = [ ... path('assembly/<slug:slug>/', views.AssemblyDetailView.as_view(), name='assembly-detail') ] This URL works: 127.0.0.1:8000/strain/SomeAssembly-1, this one doesn't: 127.0.0.1:8000/strain/SomeAssembly.2. -
How to fix URL data retrieval with drf-multiple-model module?
I'm trying to create an API using the drf-multiple-model module but it's creating a problem with the single instance URL, as in http://localhost:8000/categories/partner-spec-categories// is returning no data available. Where could the problem be? I'm running Python 3.6.5, Django 2.2.2, MySQL 8.0.16. As of now im only focusing on the ott.cat.master.viewset, that's why the other routers don't have a base_name. urls.py router = routers.DefaultRouter() router.register(r'general-categories', gen.cat_master_viewset.CatMasterView) router.register(r'gen-cat-settings', gen.cat_settings_viewset.CatSettingsView) router.register(r'partner-spec-catagories', ott.cat_master_viewset.CatMasterView,base_name='partner-spec-catagories') router.register(r'spec-cat-settings', ott.cat_settings_viewset.CatSettingsView) The viewset.py file I'm having problems with class CatMasterView(FlatMultipleModelAPIViewSet,viewsets.ModelViewSet): all_or_none_response = False def partner_id_filter(queryset,request,*args,**kwargs): global all_or_none_response final_queryset = queryset if PartnerMaster.objects.filter(partner_id=request.query_params.get('partner_id')).exists(): partner_to_get = request.query_params.get('partner_id') if partner_to_get == None: all_or_none_response = False else: all_or_none_response = True final_queryset = final_queryset.filter(partner_id=partner_to_get) if OttCategoryMaster.objects.filter(id=request.query_params.get('id')).exists(): id_to_get = request.query_params.get('id') if id_to_get == None: all_or_none_response = False else: all_or_none_response = True final_queryset = final_queryset.filter(id=id_to_get) if OttCategoryMaster.objects.filter(name=request.query_params.get('name')).exists(): name_to_get = request.query_params.get('name') if name_to_get == None: all_or_none_response = False else: all_or_none_response = True final_queryset = final_queryset.filter(name=name_to_get) return final_queryset def all_or_none_response_filter(queryset,request,response=all_or_none_response,*args,**kwargs): if response: pass else: queryset = None if PartnerMaster.objects.filter(partner_id=request.query_params.get('partner_id')).exists(): pass else: queryset = None return queryset querylist = [ {'queryset':OttCategoryMaster.objects.all(), 'serializer_class':ott_cat_master_serializer, 'label':'ott_categories', 'filter_fn':partner_id_filter,}, {'queryset':CategoryMaster.objects.all(), 'serializer_class':gen_cat_master_serializer, 'label':'gen_categories', 'filter_fn':all_or_none_response_filter} ] def get_serializer_class(self): return ott_cat_master_serializer Although filtering .../?id=1 works, using .../1/ doesn't which should essentially return the same thing. -
Retrieving attributes from a one to one related model's foreign key related field
So I have three models which are related to each other in different relations. First, the Parent model, which is related to the student using one to one relation also the student model is related to the attendance model using a foreign key relation. I want to create a serializer where I can retrieve the attendance of each parent's child separately. How can this be done? models.py class Parent(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True, default=None) child = models.ForeignKey(Student, on_delete=models.CASCADE) email = models.EmailField(null=True) def __str__(self): return self.user.firstName + ' ' + self.user.lastName class Student(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True, default=None) batch = models.ForeignKey(Batch, on_delete=models.CASCADE, null=True, related_name='students') age = models.IntegerField(blank=True) @property def remarks(self): return self.remark_set.all() @property def marks(self): return self.marks_set.all() def __str__(self): return self.user.firstName + ' ' + self.user.lastName class Attendance(models.Model): Subject = models.ForeignKey(Subject, on_delete=models.CASCADE, null=True) class_date = models.DateField(blank=True, null=True) student = models.ForeignKey(Student, related_name='student_today', on_delete=models.CASCADE, null=True) present = models.NullBooleanField(default=False) def __str__(self): return str(self.class_date) + '_' + str(self.student.user.username) + '_' + str(self.Subject.name) serilaizers.py class BasicUserSerializer(serializers.ModelSerializer): class Meta: model = User fields = ('firstName', 'lastName') class BasicStudentSerializer(serializers.ModelSerializer): class Meta: model = Student fields = ('batch', 'age') class ParentSerializer(serializers.ModelSerializer): user = BasicUserSerializer(read_only=True, many=False) child = BasicStudentSerializer(read_only=True, many= False) class Meta: model = Parent fields = … -
Django formtools SessionWizardView repopulating form on validation error
I've a django-formtools SessionWizardView wizard which works fine when all data is input. However, I have form validation going on within each step of the form and if a step is represented I cannot get the entered data to redisplay in some instances. Here is a simple example. Required field description isn't entered byt field plan was entered. The validation error is reported and the form redisplayed. I'm creating the plan checkboxes in the template as below. {% for plan in PLANS %} <div class="col-6"> <span class="form-radio form-radio-xl"> <input type="radio" id="id_job-plan_{{plan.id}}" name="job-plan" value="{{ plan.pk }}" required {% if wizard.form.plan.value == plan.pk %}checked{% endif %}> <label for="id_job-plan_{{plan.id}}">{{ plan }} - {{plan.pk}} </label> </span> </div> {% endfor %} I expect {% if wizard.form.plan.value == plan.pk %}checked{% endif %} to be True in one instance and therefore checked. It isn't and I do not understand why not. If I do {{ wizard.form.plan.value }} the displayed result looks the same as {{ plan.pk }} -
How to upload a CSV file to a Django Rest API and how to access it?
I want to know how to upload multiple csv files to django rest api , how to access them and how to export csv files from django rest api. I have installed django-rest-framework-csv.I saw the example provided here is the link to the same link to the example.I installed and did all the migrations. This is the views.py from django.urls import reverse from rest_framework import viewsets, status from rest_framework.decorators import list_route from rest_framework.response import Response from rest_framework.settings import api_settings from rest_framework_csv.parsers import CSVParser from rest_framework_csv.renderers import CSVRenderer from example.serializers import TalkSerializer from example.models import Talk class TalkViewSet(viewsets.ModelViewSet): """ API endpoint that allows talks to be viewed or edited. """ queryset = Talk.objects.all() parser_classes = (CSVParser,) + tuple(api_settings.DEFAULT_PARSER_CLASSES) renderer_classes = (CSVRenderer,) + tuple(api_settings.DEFAULT_RENDERER_CLASSES) serializer_class = TalkSerializer def get_renderer_context(self): context = super(TalkViewSet, self).get_renderer_context() context['header'] = ( self.request.GET['fields'].split(',') if 'fields' in self.request.GET else None) return context @list_route(methods=['POST']) def bulk_upload(self, request, *args, **kwargs): """ Try out this view with the following curl command: curl -X POST http://localhost:8000/talks/bulk_upload/ \ -d "speaker,topic,scheduled_at Ana Balica,Testing,2016-11-03T15:15:00+01:00 Aymeric Augustin,Debugging,2016-11-03T16:15:00+01:00" \ -H "Content-type: text/csv" \ -H "Accept: text/csv" """ serializer = self.get_serializer(data=request.data, many=True) serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data, status=status.HTTP_303_SEE_OTHER, headers={'Location': reverse('talk-list')}) curl -X POST http://localhost:8000/talks/bulk_upload/ \ -d "speaker,topic,scheduled_at Ana Balica,Testing,2016-11-03T15:15:00+01:00 Aymeric … -
Access User’s value in model’s file
I would like to ask if is possible when I have something like this >>> from django.contrib.auth.models import User >>> u = User.objects.get(username='marcel4') >>> d = u.employee.department >>> print(d) >>> 経理部 To be able to access that ‘d’ for all Users in ‘models.py’ file. Because I want to be able to do ‘if’ statement depending on the ‘d’ -
How can I send the image to database with form initialized with model data?
I have my form GoodGet: class GoodGet(forms.ModelForm): class Meta: model = Good_Get Size = forms.ModelChoiceField(queryset = Good.objects.all()) fields = '__all__' widgets = { 'Name': forms.TextInput(attrs = {'type': 'hidden'}), } def __init__(self, *args, good_id1=None, **kwargs): super(forms.ModelForm, self).__init__(*args, **kwargs) if good_id1 is not None: obj = Good.objects.filter(id = good_id1) for good in obj: good_sizes = good.Size.all() self.fields['Size'].queryset = good_sizes I initialized this form with data from model "Good" in views.py: class Adding(View): def get(self, request, good_id): good = Good.objects.filter(id = good_id) good1 = Good.objects.get(id = good_id) form = GoodGet(initial = {'Photo': good1.Photo, 'Name': good1.Name, 'Price': good1.Price}, good_id1 = good_id) return render(request, 'HiPage/add_to_cart.html', context = {'form': form, 'good': good}) def post(self, request, good_id): good1 = Good.objects.get(id = good_id) form = GoodGet(request.POST, initial = {'Photo': good1.Photo, 'Name': good1.Name, 'Price': good1.Price}, good_id1 = good_id) if form.is_valid(): form.save() return redirect('/cart') good = Good.objects.filter(good_id1 = good_id) return render(request, 'HiPage/add_to_cart.html', context = {'form': form, 'good': good}) CharFields "Name" and "Price" are saved to database, but not ImageField "Photo"... On site I can see that, so initialization works well But when I click "submit" everything is saved except Photo... How can I fix it? Models "Good" and "Good_Get" if u need: class Good(models.Model): Name = models.CharField(max_length = 150) Type … -
How to get all pages details by filtering by cms page type?
I am new to django and I want to get all page details filtering by page type in django-cms. I used below def to display it in a template. def cms_detailed_view(request): all_pages = Title.objects.public().values() context= {'pages': all_pages} return render(request, 'node-detailed.html', context) It gives all pages. But I wants to filter it by page type. I don't know how to use filter method to filter by page type like all_pages = Title.objects.filter(type="pagetype") -
How can I make OR expression with django-filrers DRF?
I use Angular on frontend and django-rest-framework on backend. User want to use customer filter by city and region. One region include few cities. Filter code: class CustomerFilter(filterset.FilterSet): city = filters.ModelMultipleChoiceFilter(queryset=City.objects.all()) region = filters.ModelMultipleChoiceFilter(method='filter_regions', queryset=Region.objects.all()) class Meta: model = Customer fields = ['city'] def filter_regions(self, queryset, name, value): if not value: return queryset return queryset.filter(city__region__in=value) As result I want to see customers from specified cities OR reqions. For example: /api/customers/?city=32&region=10 Return customers who live inside intersection of cities region 10 and city 32, but I need all customers who live inside one of both sets. -
How to update different queryset objects with a ModelForm in Django
I have two models as follows class Professor(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) faculty_id = models.IntegerField(primary_key=True) name = models.CharField(blank=True, max_length=50) family_name = models.CharField(blank=True, max_length=50) birth_date = models.DateField(blank=True, null=True) national_id = models.IntegerField(blank=True, null=True) .... And: class Journal(models.Model): professor = models.ForeignKey(Professor, on_delete=models.CASCADE) title = models.CharField(max_length=1000, null=True) title_english = models.CharField(max_length=1000, null=True) magazine_title = models.CharField(max_length=1000, null=True) magazine_title_english = models.CharField(max_length=1000, null=True) ... I have a view which lists all the journals the belong to a professor: def journals_update(request): professor = get_object_or_404(Professor, user__username=request.user) context = {"active_tab": "3-1", "active": "made-3", "journals": Journal.objects.filter(professor=professor)} return render(request, 'journals.html', context=context) I want to be able to change the fields related to different objects that are rendered in the journals.html and save the fields that are changed when the user post it. I have tried things like the following: def post(self, request): queryset = self.get_queryset() form = JournalModelForm(request.POST) if form.is_valid(): data = form.cleaned_data print(data) queryset.update(**data) But I realized queryset.update() updates the fields in with the same value. How can I go about this? I would very much prefer to to it with generic views. -
Uncaught TypeError: Failed to execute 'serializeToString' on 'XMLSerializer': Failing to download an svg (created with D3.js) as png/pdf
I am trying to download a graph that I created with d3.js as an png (Any datatyp would do though), but I am failing gloriously. I followed various questions on Stackoverflow which address similar issues, but still can't get it to work. With different solutions I very often run into this error when debugging: Uncaught TypeError: Failed to execute 'serializeToString' on 'XMLSerializer': parameter 1 is not of type 'Node'. This is my code for my svg-graph: var data = build // set the dimensions and margins of the graph var margin = {top: 20, right: 20, bottom: 30, left: 100}, width = 960 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; // set the ranges var y = d3.scaleBand() .range([height, 0]) .padding(0.1); var x = d3.scaleLinear() .range([0, width]); // append the svg object to the body of the page // append a 'group' element to 'svg' // moves the 'group' element to the top left margin var svg = d3.select(".svg-net-area").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); // format the data data.forEach(function(d) { d.buildings__net_leased_area = +d.buildings__net_leased_area; }); // Scale the range … -
Django: settings.DATABASES is improperly configured
I know I am not the first person to ask this question, but I still couldn't find an answer for my situation. I have a Django environment that works very well, I know I only have one (1) settings.py file and I know that my environment accesses it correctly. I recently added a new endpoint to my project. I defined its URL in urls.py urlpatterns = [ ... url(PREFIX + r"^v1/alerts/debug$", alerts_views_v1.debug_trigger_alert_notification), ... ] It is connected to a method that is in a the file alerts/views_v1.py but is not in any particular class: @api_view(["POST"]) def debug_trigger_alert_notification(request): """ Trigger an Alert. i.e. Create an Alertnotification. This function is meant to be called by the scheduler service. """ workspace_slug = request.data.pop("workspace") with in_database(workspace_slug, write=True): serializer = AlertNotificationSerializer(data=request.data) if serializer.is_valid(raise_exception=True): serializer.save() return Response() When I send a request to this URL, I receive the following 500 error: ImproperlyConfigured at /v1/alerts/debug settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. In my settings.py file, my DATABASES variable seems correct (though it is built in a roundabout way): DEFAULT_DATABASES = { "default": { # This DB is supposed to always have the latest version of the schema described … -
how django can filter data from csv and sort it to specific entity to db
i have a model products > product, quantity I need to upload a csv with product id and a quantity of it. my issue is how to make understand to django which quantity add to which product meanwhile it's uploading a csv. Could to kindly recommend me something to solve this issue? Thank you. -
Django ORM relation one-to-many
I have a model: class Product(models.Model): title = models.CharField(max_length=200) url = models.URLField() pub_date = models.DateTimeField() votes_total = models.IntegerField(default=1) image = models.ImageField(upload_to='images/') icon = models.ImageField(upload_to='images/') body = models.TextField() hunter = models.ForeignKey(User, on_delete=models.CASCADE) Now I'd like to add a functionality of upvoters to know on what products user has already voted. I tried to add the next field but cannot make a migration even if default field is provided. Also I tried to clear the database but again cannot make it work. upvoters = models.ForeignKey(User, on_delete=models.CASCADE, related_name='upvoted') I suppose it works the next way: Field to determine upvoted products. To check if user has been upvoted on product, call: User.upvoted.filter(id=product.id).count() == 1 This means that user has already upvoted on this product. What's wrong? What should I change to make it work? -
How to save the attribute of my ForeignKey?
I am trying to create a view that allows users to upload their documents in my Lessons model. However when documents are uploaded, I am not able to save the instance in which the form is being submitted. When I access the admin page, the field for my ForeignKey is left empty. This is the views.py for users to submit their documents: class UploadLessonView(CreateView): model = Lesson fields = ['title', 'file'] template_name = 'store/upload_lesson.html' success_url = '../' def form_valid(self, form): form.instance.author = self.request.user return super(UploadLessonView, self).form_valid(form) This is the models.py for my child model: class Lesson(models.Model): title = models.CharField(max_length=100) file = models.FileField(upload_to="lesson/pdf") date_posted = models.DateTimeField(default=timezone.now) post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True, blank=True) def __str__(self): return self.title def get_absolute_url(self): return reverse('lesson_upload', kwargs={'pk': self.pk}) For my parent model: class Post(models.Model): title = models.CharField(max_length=100) image = models.ImageField(default = 'default0.jpg', upload_to='course_image/') description = models.TextField() price = models.DecimalField(decimal_places=2, max_digits=6) date_posted = models.DateTimeField(default=timezone.now) author = models.ForeignKey(User, on_delete=models.CASCADE) rating = models.IntegerField(default = 0) def __str__(self): return self.title def get_absolute_url(self): return reverse('post-detail', kwargs={'pk' : self.pk}) Field for Post is left empty when I submit documents. -
Why do I get 'NoneType' object is not callable when trying to delete item with m2m relations?
I'm writing an app to represent some systems : some equipments will contain hardware articles, for exemple a server will contain hard drives. When I delete an equipment which m2m relation is not set it works fine, but I get an error when it is. Here is a simplified version of the model scheme. class Hardware(models.Model): equipment = models.ManyToManyField('Equipment', blank=True, through='HardwareEQ') # attributes class HardwareEQ(models.Model): hardware = models.ForeignKey(Hardware, on_delete=models.CASCADE) equipment = models.ForeignKey(Equipment, on_delete=models.CASCADE) # relation attributes Below is full traceback. Traceback: File "C:\Users\USER\Envs\venv\lib\site-packages\django\core\handlers\exception.py" in inner 34. response = get_response(request) File "C:\Users\USER\Envs\venv\lib\site-packages\django\core\handlers\base.py" in _get_response 115. response = self.process_exception_by_middleware(e, request) File "C:\Users\USER\Envs\venv\lib\site-packages\django\core\handlers\base.py" in _get_response 113. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\USER\Envs\venv\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view 54. return view_func(*args, **kwargs) File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\viewsets.py" in view 103. return self.dispatch(request, *args, **kwargs) File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\views.py" in dispatch 483. response = self.handle_exception(exc) File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\views.py" in handle_exception 443. self.raise_uncaught_exception(exc) File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\views.py" in dispatch 480. response = handler(request, *args, **kwargs) File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\mixins.py" in destroy 93. self.perform_destroy(instance) File "C:\Users\USER\Envs\venv\lib\site-packages\rest_framework\mixins.py" in perform_destroy 97. instance.delete() File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\base.py" in delete 918. collector.collect([self], keep_parents=keep_parents) File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\deletion.py" in collect 224. field.remote_field.on_delete(self, field, sub_objs, self.using) File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\deletion.py" in CASCADE 16. source_attr=field.name, nullable=field.null) File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\deletion.py" in collect 220. sub_objs = self.related_objects(related, batch) File "C:\Users\USER\Envs\venv\lib\site-packages\django\db\models\deletion.py" in related_objects 236. **{"%s__in" % … -
Django creating a custom search_field
I have two models and i want to search the numero of Ramal in Avaria'model. how can i do that in simple way? Model1 class Avaria(models.Model): ..... ..... Model2 class Ramal(models.Model): numero = models.PositiveIntegerField(blank=True,verbose_name="Numero do ramal", primary_key=True, null=False) avaria = models.ForeignKey(Avaria,on_delete=models.CASCADE,related_name='RamalObjects',) Model1admin class RamalInline(admin.StackedInline): model = Ramal extra = 0 class AvariaAdmin(admin.ModelAdmin): search_fields = ['id','Ramal__numero'] inlines = [RamalInline] -
docker compose with celery and rabbit mq
I am starting a big python project which will be split into components, each of which will integrate with a different system, and i plan to pass tasks between each component using Celery and a message broker, I think RabbitMQ. the components are as follows: Integrates with external system and sends/receives messages (soap unfortunately) Interface for Ops to manage messages (django site) Sends/receives data from internal system A Sends data to internal system B Messaging component, manages communication between all other components (Rabbit MQ) I plan to use docker-compose and host each component in it's own container, as well as a separate container for rabbitMQ and one for celery-beat if needed. What i want to know is, what is the best way to actually share the celery scripts between each container? Should i place all of the code on all containers, with each container only using the code it needs, or should i place only the necessary code on each container, and somehow share my tasks.py and celery_config.py between the containers? I am also not sure how to manage version control in this case, should i have one .git in the root of my project, or should I have one … -
Django-like model management
is there a Python module that let's me define models and save objects to a database, similar to what Django does, just without the "other stuff" around it? -
Getting a v alue from app for specific user
I have a Calendar app, which has a Event class for title, description, start_time, end_time, choices fields. I added the choices field with two choices c =[("1", "経理部"), ("2", "管理部")] I also added a a column to User model with this class class Employee(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) department = models.CharField(max_length=100) I'm able to access this department field with this code to shell >>> from django.contrib.auth.models import User >>> u = User.objects.get(username='marcel4') >>> d = u.employee.department >>> print(d) >>> 経理部 And simply I would like to save a post (Event) in calendar app with '経理部' choice and be able to see that post only with account that has department set to 経理部 (same one) Where should I make a changes? (like if or so) Here are my codes models in calendar class Event(models.Model): c =[("1", "経理部"), ("2", "管理部")] title = models.CharField(max_length=100) description = models.TextField() start_time = models.DateTimeField(default='2019-06-18T16:00') end_time = models.DateTimeField(default='2019-06-18T17:00') choices = models.CharField(max_length=1, choices=c) @property def get_html_url(self): url = reverse('cal:event_edit', args=(self.id,)) return f'<a href="{url}"> {self.title} </a>' views in calendar class CalendarView(LoginRequiredMixin, generic.ListView): model = Event template_name = 'cal/calendar.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) d = get_date(self.request.GET.get('month', None)) cal = Calendar(d.year, d.month) html_cal = cal.formatmonth(withyear=True) context['calendar'] = mark_safe(html_cal) context['prev_month'] = … -
Deployment architecture for a analytics web baszed application that uses django and spark frameworks
I am developing a web based analytics application which will provide model training and testing features via UI. To do this i had used django with scikit learn. Now, I want to do this at big data scale using spark. Using django as the backend framework for handling requests and spark to do the processing and modelling I had setup a django project and setup spark on a cluster of two linux machines along with hdfs. I am assuming that uploading / downloading / streaming of data to that hdfs is already implemented. I write each model as a view in the django project and the implementation of the view has code written using pyspark. I had used pyspark to create a connection to the spark setup on linux cluster. import pandas as pd import numpy as np import os from pyspark import SparkConf, SparkContext from pyspark.sql import SparkSession from pyspark.ml import Pipeline from pyspark.ml.feature import StringIndexer, VectorAssembler, IndexToString from pyspark.ml.classification import DecisionTreeClassifier from pyspark.ml.evaluation import MulticlassClassificationEvaluator def sample_model_code(trainData, trainDataFileType, trainDataDelimiter, testData, testDataFileType, testDataDelimiter, targetIndexTrainData, targetIndexTestData, modelName): # trainData = "D:/training-data.csv" # trainDataFileType = "csv" # trainDataDelimiter = "," # testData = "D:/test-data.csv" # testDataFileType = "csv" # testDataDelimiter = … -
Django : Display user object of logged in user in admin page
I have a set of users in my django application. I want them to be able to only see/change their user object in the admin page. So far, I made a group that restricts all permissions to the user object and then added a object permission using django-guardian, this does indeed do the job but it does not display the user object in the admin page however it does enable the user from accessing his record through code. I essentially am looking for something like user_passes_test for the admin page. -
Error with Django: gunicorn: command not found
Below is the few lines of log obtained from heroku logs while testing a django app I created. The error from the log seems to be "bash: gunicorn: command not found". Please suggest how to stop the error and run the app. 2019-0624T09:36:40.536849+00:00 heroku[web.1]: Starting process with command `gunicorn pages_project.wsgi --log-file -` 2019-06-24T09:36:42.131706+00:00 heroku[web.1]: State changed from starting to crashed 2019-06-24T09:36:42.137706+00:00 heroku[web.1]: State changed from crashed to starting 2019-06-24T09:36:42.051277+00:00 app[web.1]: bash: gunicorn: command not found 2019-06-24T09:36:42.111756+00:00 heroku[web.1]: Process exited with status 127 2019-06-24T09:36:45.000000+00:00 app[api]: Build succeeded 2019-06-24T09:36:48.595597+00:00 heroku[web.1]: Starting process with command `gunicorn pages_project.wsgi --log-file -` 2019-06-24T09:36:51.225166+00:00 heroku[web.1]: State changed from starting to crashed 2019-06-24T09:36:51.204050+00:00 heroku[web.1]: Process exited with status 127 2019-06-24T09:36:51.147676+00:00 app[web.1]: bash: gunicorn: command not found