Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
can't install pandas using docker-compose
I don't know if this is docker-related or pandas or me. I have a docker container for Django that worked perfectly fine, up until the point I needed to add Pandas. I have tried to install via requirements.txt as follows: Django>=2.0 psycopg2 python-decouple>=3.1 selenium>=3.7.0 ipdb==0.10.3 argon2-cffi>=18.1.0 django-widget-tweaks>=1.4.1 pandas==0.22 with the RUN pip install -r requirements.txt command in the Dockerfile. This works for all other python packages I've tried but not for pandas. Then I tried to run the command from the Dockerfile with different variations of RUN apt-get update && apt-get install -y python3-pandas or RUN pip install pandas No matter the approach, I try to run docker-compose up on the Django container and I get ImportError: no module named pandas Would appreciate any insight. -
Openedx Native installation : theme change not working
I have installed openedx using Native installation method. Now I want to change the default logo. As a test, i removed the logo from the folder /edx/app/edxapp/edx-platform/lms/static/images. But when i open the localhost, its still there. (lms view). In inspect view, the logo name appears as /static/images/logo.b6c374d66d57.png. The same operation when I perform in devstack, The logo changes successfully. What am I missing? Since I am using the default theme, I think I don't need to configure anything regarding theme customization. -
Does "to_internal_value" work for generic fields in Django REST Framework?
to_internal_value usually get a dict with data and return class object, but in django's generic models, you must provide object_id, but how will you provide an object_id if it's not created yet ? -
Combine two distinct views into a single page in django
Old setup object_list.html and object_edit.html used their own views and functionality was split on two separate pages # views.py class ObjectList(ListView): def get_context_data(self, **kwargs): ... def get_queryset(self): ... class ObjectUpdate(UpdateView): def get_object(self, queryset=None): ... def get_form(self, form_class=None): ... def form_valid(self, form): ... def get_form_class(self): ... # urls.py url(r'^objects/$', ObjectList.as_view(), name='object-list'), url(r'^objects/(?P<pk>[^/]+)/edit/$', ObjectUpdate.as_view(), name='object-edit'), New We want to split list and edit into smaller components and include them in a single base html file. e.g. object_base.html and ObjectBase {% include "object_list.html" %} {% include "object_edit.html" %} class ScheduleBase(???): template_name = "object_base.html" What is the correct way to combine or import existing views into a single page? Should I just combine them into a single view while doing other refactoring? -
NOT NULL constraint failed: user_profile.user_id
I'm try to make Sign Up form With Profile Model and I will make some changes in the model. All tables are created when I run manage.py makemigrations but when I want to run manage.py migrate then is show this error: django.db.utils.IntegrityError: NOT NULL constraint failed: user_profile.user_id Model.py class Profile(models.Model): user = models.OneToOneField(User,default="", on_delete=models.CASCADE) bio = models.TextField(max_length=500, blank=True) location = models.CharField(max_length=30, blank=True) birth_date = models.DateField(null=True, blank=True) @receiver(post_save, sender=User) def update_user_profile(sender, instance, created, **kwargs): if created: Profile.objects.create(user=instance) instance.profile.save() Views.py: def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): user.refresh_from_db() user.profile.birth_date = form.cleaned_data.get('birth_date') raw_password = form.cleaned_data.get('password1') user.save() user = authenticate(username=user.username, password=raw_password) login(request, user) return redirect('home') else: form = SignUpForm() return render(request, 'signup.html', {'form': form}) form.py: class SignUpForm(UserCreationForm): birth_date = forms.DateField(help_text='Required. Format: YYYY-MM-DD') class Meta: model = User fields = ('username', 'birth_date', 'password1', 'password2', ) -
Django authenticate always return None
Found a lot of questions about it however couldn't find smth helps me. Settings.py contains Authentication Backend: AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', ) And auth user model: AUTH_USER_MODEL = 'users.User' User model inherits from AbstractUser class: class User(AbstractUser): <some_fields> And then 3 type of users inherit from User. I registered Client: class Client(User, models.Model): status = models.CharField(max_length=1, default='C', editable=False) <some_fields> When I activate user by activation link everything is OK. Client is authenticated user. However when I just try to enter by login and password authenticate always return None: class LoginView(APIView): def post(self, request): qs = User.objects.filter(Q(email=request.data.get('user')) | Q(phone=request.data.get('user'))) if qs.exists(): username = qs.first().username password = request.data.get('password') user = authenticate(username=username, password=password) if user is not None: login(request, user) return Response(CMD(user.id), status=status.HTTP_200_OK) return Response({ 'error': 'Invalid login / password', }, status=status.HTTP_400_BAD_REQUEST) I've logged qs which returned desired Client, also username and password are ok, but authenticate returns None. I think maybe problem is that Client isn't registered properly. This is the SignUp form: class ClientSignupForm(forms.ModelForm): class Meta: model = Client exclude = [ 'username', 'date_joined', ] def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) super(ClientSignupForm, self).__init__(*args, **kwargs) def clean(self): <actions to validate captcha> def save(self): username = 'user' + str(User.objects.all().aggregate(Max('id'))['id__max'] + 1) … -
Getting and saving value from POST with nested serializer
class InfoSerializer(serializers.ModelSerializer): class Meta: model = EventInfo fields = ('email', 'pin') class EventSerializer(DataSerializer, GeoModelAPIView): # other fields event_info = InfoSerializer(read_only=True) def create(self, validated_data): event_info = validated_data.pop('event_info', {}) event = super().create(validated_data) EventInfo.objects.create(event=event, **event_info) return event Model class EventInfo(models.Model): pin = models.CharField(max_length=60, null=False, blank=False) email = models.EmailField() event = models.ForeignKey(Event) POST { # other data "event_info": { "email": "example@example.com", "pin": "1234567890" } } So I have a model that is not visible on the browsable API, but I want to be able to save data from POST request to that model. Using this code I can create the objects and it correctly links the info to a correct Event model. However the email and pin fields won't get saved. What I have figured out is that the 'event_info' data from the POST is not visible on the validated_data. The validation goes to the DataSerializer's validation method but I guess that I should somehow bypass the validation for just the 'event_info' data? -
Changing user data in django python
guys! I'm new to django and I'm developing simple web site with user registration. I want to test some things, for example: on user profile page I added picture: and by pressing on it picture should change to: And by pressing on red one it should be changed to grey. Condotion of this picture should be saved. I have seven pictures for every day of the week and user should be able to change every picture. I've created a model like this (if you have any better ideas it would be great): class Week1(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) utr_ust0 = models.IntegerField(default=0, max_length=3) utr_ust1 = models.IntegerField(default=0, max_length=3) utr_ust2 = models.IntegerField(default=0, max_length=3) ... utr_ust0 = 0 (grey) utr_ust0 = 1 (red) But I cant't really understand how to work with this model in views. I think that during registration I should do something like this: auth.login(request, user) Week1.objects.create(utr_ust0=0, utr_ust1=0, utr_ust2=0, utr_ust3=0, utr_ust4=0, utr_ust5=0, utr_ust6=0, user_id=username) But I get this error: invalid literal for int() with base 10: 'test5' And in the function that loads page with the calendar I'm returning dict like this: if request.user.is_authenticated: content['smiles'] = [Week1.utr_ust0, Week1.utr_ust1, Week1.utr_ust2, Week1.utr_ust3, Week1.utr_ust4, Week1.utr_ust5, Week1.utr_ust6] And of course I should add some ajax … -
Responsive navbar using Django, HTML, CSS, Javascript
I am following this guideline to create a responsive navbar that, according to the dimension of the screen, will show its elements in a dropdown list (instead of an inline, used for bigger screens). Below the relevant part of the HTML (replaced some useless parts with "..." to improve and speed-up readability) <!DOCTYPE html> <html lang="en"> <head> ... <link rel="stylesheet" href="{% static 'css/styles.css' %}"> <link rel="javascript" href="{% static 'javascript/responsive.js' %}"> </head> <body> {% block sidebar %}<!-- insert default navigation text for every page -->{% endblock %} {% block content %}<!-- default content text (typically empty) --> <!-- Main Logo --> <div class="main-image" id="myMainImage"> <img src="{{STATIC_URL}}/static/images/logo.png"/> </div> <!-- Navigation Bar --> <div class="topnav" id="myTopnav"> <a href <a href="#home" class="active">Home</a> <a href="http://www...</a></li> <a href="http://www.../">Storia di Gabriella</a></li> <a href="http://www...">Video Gallery</a></li> <a href="http://www...">Photo Gallery</a></li> <a href="http://www.../">Dicono di Noi</a></li> <a href="http://www...">Come Contattarci</a></li> <input type="text" placeholder="Ricerca.."> <a href="javascript:void(0);" class="icon" onclick="respScreen()">&#9776;</a> </div> in the static folder (mysite/articles/static) I have created a javascript folder with a responsive.js file inside it /* Toggle between adding and removing the "responsive" class to topnav when the user clicks on the icon */ function respScreen() { var x = document.getElementById("myTopnav"); if (x.className === "topnav") { x.className += " responsive"; } else { … -
Is it bad to dynamically create Django views?
I wanted to add a generic create form for every model in my app. After repeating the same few lines over and over only changing the model name the DRY principle called out to me. I came up with the following method to dynamically add a form, view, and route for each model in my app. forms.py from django import forms from . import models import inspect from django.db.models.base import ModelBase # Add ModelForm for each model for name, obj in inspect.getmembers(models): if inspect.isclass(obj) and isinstance(obj, ModelBase): vars()[name + "ModelForm"] = forms.modelform_factory(obj, exclude=()) views.py from . import forms from . import models import inspect from django.db.models.base import ModelBase def form_factory(request, form_type, form_template, redirect_url='index', save=True): if request.method == "POST": form = form_type(request.POST) if form.is_valid(): if save: form.save() return HttpResponseRedirect(reverse(redirect_url)) else: form = form_type() return render(request, form_template, {'form': form}) # Add view for each model for name, obj in inspect.getmembers(models): if inspect.isclass(obj) and isinstance(obj, ModelBase): form = getattr(forms, name + "ModelForm") func = lambda request: form_factory(request, form, 'core/create.html') name = 'create_' + name.lower() vars()[name] = func urls.py from django.urls import path from . import views from . import models import inspect from django.db.models.base import ModelBase existing_urls = [] for urlpattern in urlpatterns: … -
unable to add a variable as parameter in url with django
I'm using django ver. 2.0.3, with python 3.6 and following models @python_2_unicode_compatible class ArticleDb(models.Model): slug = models.SlugField(primary_key=True, unique=True, blank=True) title = models.CharField(max_length=200, validators=[MinLengthValidator(5)]) content = models.TextField(max_length=5000) then I have following template {% for article in articles %} <tr> <td>{{ article.title }}</td> <td><a href="{% url 'view_article' slug_addr= article.slug %}">{{ article.slug }}</a></td> </tr> {% endfor %} the url.py is following ... path('code/<slug:slug_addr>/', views.ViewArticle.as_view(), name="view_article"), ... so the problem is slug_addr= if I assign a string value it works but if I put template variables like article.slug don't works, althought {{article.slug}} works, every time I get this error: Reverse for 'view_article' with keyword arguments '{'slug_addr': ''}' not found. 1 pattern(s) tried: ['code\\/(?P<slug_addr>[-a-zA-Z0-9_]+)\\/$'] -
RuntimeError: populate() isn't reentrant
I got a legacy project based on Django as backend and Angularjs on the front. It's deployed and working, but I got no docs at all so I had to guess everything out of how to deploy it in local, how the system works and that. Now, I've been asked to set it up in a pre-production environment, and so I tried to do, I copied all the configs from the production server and changed as necessary to fit the new environment [Thu Mar 15 07:08:53.612256 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] mod_wsgi (pid=13884): Target WSGI script '/opt/mysite/mysite/wsgi.py' cannot be loaded as Python module. [Thu Mar 15 07:08:53.612336 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] mod_wsgi (pid=13884): Exception occurred processing WSGI script '/opt/mysite/mysite/wsgi.py'. [Thu Mar 15 07:08:53.612539 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] Traceback (most recent call last): [Thu Mar 15 07:08:53.612602 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] File "/opt/mysite/mysite/wsgi.py", line 19, in <module> [Thu Mar 15 07:08:53.612611 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] application = get_wsgi_application() [Thu Mar 15 07:08:53.612624 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] File "/usr/local/lib/python3.6/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application [Thu Mar 15 07:08:53.612632 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] django.setup(set_prefix=False) … -
How to create content_type object in DRF?
Generic model - Phone class Phone(Model): number = CharField(max_length=50) content_type = ForeignKey(ContentType, on_delete=CASCADE) object_id = PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') Model - Client class Client(Model): title = CharField(max_length=100) phones = GenericRelation(Phone) Serializer - Client class ClientSerializer(ModelSerializer): title = CharField(required=True) phones = PhoneObjectRelatedField(queryset=Phone.objects.all(), many=True, required=False) Serializer - Phone class PhoneObjectRelatedField(RelatedField): def to_representation(self, obj): data = { 'number': obj.number } return data def to_internal_value(self, data): phone = Phone.objects.create( number=data['number'], object_id=???, content_type_id=5 ) return phone POST-Request body { "title": "John", "phones": [ { "number": "1-123456789" }, { "number": "2-123456789" } ] } Problem The problem is that while creating new Client, I cannot provide current Client's ID for his phones (obviously because current Client is not created yet, so he has no ID yet). As you can see in 'to_internal_value' method, I need both 'content_type_id' and 'object_id' for create new Phone for current Client, and I can provide 'content_type_id' because it's known already for Client class. But I can't provide 'object_id'. What should I do ? -
Hide model from main admin list
In my Django app, I have an Attribute model which has a many-to-many relationship to a MeasurementMethod model. I put an inline for MeasurementMethod in the admin interface for Attribute, but I don't think it is useful to have a separate interface for managing MeasurementMethods at all; there's no reason why a user would say, "Gee, I wonder what Attributes can be measured by water displacement." However, this left no way to create new MeasurementMethods from the inline editor until I found Anton Belonovich's post, which says that I need to admin.model.register(MeasurementMethod) first. I did that, and sure enough the edit and create buttons appeared. But now on the admin page, where there's a list of apps and the models that can be managed, there's an entry for MeasurementMethod that I don't want. Is there a way to get rid of it? Or is there a better way to accomplish this? -
Not able to connect mysql with python 2.7 in django 1.11 getting error while installing mysqlclient and MySQL-python both
i am trying to install mysql client to connect mysql with python 2.7 for django project but getting error, even i tried MySQL-python connector to install but getting error there also. C:\Users\syedabdul\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dve rsion_info=(1,3,12,'final',0) -D__version__=1.3.12 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -Ic:\python27\include -Ic:\pyt hon27\PC /Tc_mysql.c /Fobuild\temp.win32-2.7\Release\_mysql.obj /Zl _mysql.c _mysql.c(29) : fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory error: command 'C:\\Users\\syedabdul\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2 ---------------------------------------- Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\syedab~1\\appdata\\local\\temp\\pip-build-xgy30p\\mysqlc lient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec')) " install --record c:\users\syedab~1\appdata\local\temp\pip-rs9dvc-record\install-record.txt --single-version-externally-managed --compile" fail ed with error code 1 in c:\users\syedab~1\appdata\local\temp\pip-build-xgy30p\mysqlclient\ -
Django with and without Nginx
I am using Django to develop a web application on the linux server. When it comes to deployment, a proposed way is to use Nginx to communicate with the client and Django only need to communicate with Nginx with uwsgi protocol. The relationship is client<-Http->Nginx<-uwsgi->Django server Latter I found that I can also push the server on public network with python manage.py runserver 0:0:0:0 It seems that the Nginx can help serve the static file and media. My question is, what is exactly the benefit of using Nginx as the middleman? -
Something goes wrong when use uwsgi with my django application
Well. It's hard to describe what have happended on me. When I ran my django applicetion with commands python manage.py runserver it was ok to authenticate and login in. But When I ran it with uwsgi. I got a mistake which said FieldDoesNotExist: The fields "set(['area_id'])" do not exist on the document "User".However,I am sure I have defined that filed in my document. And here is my debug page on chrome I use python2.7 and django1.8.6 and the database is mongodb -
What is the way to create the Quiz Experience for the appearing candidate for Django Quiz app
For a QUIZ Django project, we have, an almost ready back-end for creating questions and answers. Now , I want to know, how will we organize this quiz? Some points regarding this: Start the quiz which will go throw N diff questions . So does the student login or just enter some basic info like email and name, and just starts by , lets say some button "Start Quiz". A timer also should be shown indicating remaining time. What if different questions need different timers . Like difficult questions 2 mins, but easy ones only 1 min. User should not be able to reset this timer by any means (resubmit page or restart quiz). There needs to be a result page to show Summary . Should this "Result" be a model? (I think yes). How do we ensure , user cannot retake the exam ? I started with this idea , but I can't get past the timer thing. How do we implement this? Ideas: Should we use Django sessions? How?. Or this should be done using Javascript?. Should the client tell the server, if the time is almost over or the back-end server should send a signal . -
How to retrieve data from an existing db file and display it on webpage using Django?
This is the views.py file: from django.shortcuts import render from django.views.generic import TemplateView from .models import Report import random Create your views here. class HomePageView(TemplateView): def get(self, request, **kwargs): args = {} data = Report.objects.all() args['data'] = data return render(request, 'index.html',args) -
Prevent user to access my website's service more than once without signup
I am building a web app with Python, Django and I want certain service available on my website to be accessed only once by a user/client if he/she is not a registered user. How can I identify whether the same user/client has accessed the system before without registering and if yes the access to the service must be blocked. I have tried using the IP address of the user's system but person with a different network on the same machine can still access the service which I don't want. Any kind of help will be very helpful for me. -
Read and process multiple json files in python
I'm trying to process many json files with user input. If there are three indentical data ["a","a","a"] in GeneListA, I suppose it is going to run the code three times with jsonurl = "http://abc.def/a/format=json" However, I got the error : Traceback (most recent call last): File "/Users/me/miniconda3/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner response = get_response(request) File "/Users/me/miniconda3/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/me/miniconda3/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/me/Desktop/Project/gsea/analysis/views.py", line 49, in result for gene in data[0][gidA]: KeyError: 'NC_000913\r\nNC_000913\r\nNC_000913' And here is my code: AGOAnnos = [] for genefromlist in GeneListA: jsonurl = "http://abc.def/"+genefromlist+"/format=json" print(jsonurl) with urllib.request.urlopen(jsonurl) as url: data = json.loads(url.read().decode()) for gene in data[0][gidA]: for anno in data[0][gidA][gene]: if type(anno) is dict: GOAnno = re.search(r'GO:\d+',anno["ID"]) if GOAnno: AGOAnnos.append(GOAnno.group()) elif type(anno) is str: GOAnno = re.search(r'GO:\d+',anno) if GOAnno: AGOAnnos.append(GOAnno.group()) -
Accessing an image in an httpresponse
I have a django test method that is supposed to test that the correct image was returned in an httpresponse. Here is the code for the test: c = Client() originalFilePath = '../static_cdn/test.jpg' image_data = open(originalFilePath, "rb") with open(originalFilePath, "rb") as fp: response = c.post('/', {'image': fp}) self.assertEqual(image_data,response) The test isn't working because I'm comparing the opened image with the entire http response instead of just the image it has. I've tried to access the image by checking for fields it may have but it doesn't appear to have any. In the view I'm returning the image using HttpResponse(image_data, content_type="image/jpg") and from looking at the fields from the class in the docs I'm not seeing a field that would return the image. How can I access the image from the httpresponse so that it can be tested? -
Different Size Options in Django and Swift
I'm working on an app that will allow users to select different sizes on their products that will be related to a Django server. Right now the model that I'm using is: SIZE = ( ('Sizes',( ('small', 'Small'), ('medium', 'Medium'), ('large', 'Large'), ('XL', 'Extral Large'), ('xxl', 'Extra Extra Large'), )), ) sizes = MultiSelectField(choices=SIZE, max_choices=32, max_length=32) price = models.DecimalField(decimal_places=2, max_digits=4) What I want to do is have restaurant put in the the price at each individual size but, I'm not sure the best way to do this. How would I convert the form to combine Size and price? Also, since I'm going to be pull this into my API, how would I populate this dictionary into my app? -
Error: could not determine PostgreSQL version from '10.3' - Django on Heroku
I tried to push from local env to Heroku master. No new requirements from the previous commit. However, I received an Error which saying the system could not determine PostgreSQL version from "10.3". Here is my requirements list: amqp==1.4.9 anyjson==0.3.3 appdirs==1.4.3 awscli==1.11.89 billiard==3.3.0.23 boto==2.46.1 botocore==1.5.52 celery==3.1.25 Collectfast==0.5.2 colorama==0.3.7 dj-database-url==0.4.2 Django==1.11.1 django-celery==3.2.1 django-recaptcha==1.3.0 django-redis-cache==1.7.1 django-storages==1.5.2 django-storages-redux==1.3.2 docutils==0.13.1 gunicorn==19.7.0 honcho==0.5.0 jmespath==0.9.2 kombu==3.0.37 olefile==0.44 packaging==16.8 Pillow==4.3.0 psycopg2==2.6.2 pyasn1==0.2.3 pyparsing==2.2.0 python-dateutil==2.6.0 pytz==2018.3 PyYAML==3.12 redis==2.10.5 reportlab==3.4.0 rsa==3.4.2 s3transfer==0.1.10 selenium==3.4.0 six==1.10.0 vine==1.1.4 virtualenv==15.1.0 virtualenvwrapper-win==1.2.1 whitenoise==3.3.0 and below is the error in the build log. Collecting amqp==1.4.9 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 1)) Downloading amqp-1.4.9-py2.py3-none-any.whl (51kB) Collecting anyjson==0.3.3 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 2)) Downloading anyjson-0.3.3.tar.gz Collecting appdirs==1.4.3 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 3)) Downloading appdirs-1.4.3-py2.py3-none-any.whl Collecting awscli==1.11.89 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 4)) Downloading awscli-1.11.89-py2.py3-none-any.whl (1.2MB) Collecting billiard==3.3.0.23 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 5)) Downloading billiard-3.3.0.23.tar.gz (151kB) Collecting boto==2.46.1 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 6)) Downloading boto-2.46.1-py2.py3-none-any.whl (1.4MB) Collecting botocore==1.5.52 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 7)) Downloading botocore-1.5.52-py2.py3-none-any.whl (3.5MB) Collecting celery==3.1.25 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 8)) Downloading celery-3.1.25-py2.py3-none-any.whl (526kB) Collecting Collectfast==0.5.2 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 9)) Downloading Collectfast-0.5.2-py3-none-any.whl Collecting colorama==0.3.7 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 10)) Downloading colorama-0.3.7-py2.py3-none-any.whl Collecting dj-database-url==0.4.2 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 11)) Downloading dj_database_url-0.4.2-py2.py3-none-any.whl Collecting Django==1.11.1 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 12)) … -
manually update django model instance in put request. django django rest framework
The way I am doing my put request by exposing the parent model and then searching through the room_set becasue I need to see if the user has permissions to mess with the parent models related objects. now with that away, I am trying to do a manual put. This put will act more like a patch but the CORS policy doesn't like it when I use PATCH in my local. so I put. So Im a little confused about what to do next. How do I add the new value to my object or ignore the attribute on my model if I don't have any data on it in the request? Here is the model and the put request. class Room(models.Model): venue = models.ForeignKey(Venue, on_delete=models.CASCADE) name = models.CharField(max_length=100, null=True, blank=True) online = models.BooleanField(default=False) description = models.CharField(max_length=1000, blank=True, null=True) privateroom = models.BooleanField(default=False) semiprivateroom = models.BooleanField(default=False) seatedcapacity = models.CharField(max_length=10, null=True, blank=True) standingcapacity = models.CharField(max_length=10, null=True, blank=True) minimumspend = models.PositiveSmallIntegerField(blank=True, null=True) surroundsoundamenity = models.BooleanField(default=False) outdoorseatingamenity = models.BooleanField(default=False) stageamenity = models.BooleanField(default=False) televisionamenity = models.BooleanField(default=False) screenprojectoramenity = models.BooleanField(default=False) naturallightamenity = models.BooleanField(default=False) wifiamenity = models.BooleanField(default=False) wheelchairaccessibleamenity = models.BooleanField(default=False) cocktailseatingseatingoption = models.BooleanField(default=False) classroomseatingoption = models.BooleanField(default=False) ushapeseatingoption = models.BooleanField(default=False) sixtyroundseatingoption = models.BooleanField(default=False) boardroomseatingoption = models.BooleanField(default=False) theaterseatingoption = …