Questions tagged [django]

56179 questions
1

votes
1

answer
964

Views

How to convert django variable into json in template properly

I am using django-jsonify to convert django variable into json in javascript, and it returns such list [{"pk": 4, "model": "api.post", "fields": {"summary": "Testing", "title": "My Test"}}, {"pk": 5, "model": "api.post", "fields": {"summary": "testing again", "title": "Another test"}}] But desired...
Aydar Omurbekov
1

votes
1

answer
585

Views

Programmatically generate Django sqlsequencereset

How can I programmatically generate the SQL generated by Django's manage.py sqlsequencereset command?
Sean W.
1

votes
1

answer
619

Views

Django performing an action on a model via link

I want to, say, delete a record via a button on a website. How would I do that? Thus far every "button" or action I've done has to do with forms, which is handled via "post". The URL would stay the same, just a matter if it's a get or a post that the content and actions are different. But if I wan...
reedvoid
1

votes
1

answer
3k

Views

NoReverseMatch at /accounts/register/

I am following the getting started guide for Django registration and I am getting the following error when I visit http://localhost:8080/accounts/register/ : NoReverseMatch at /accounts/register/ Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. Request Method: GET Reques...
1

votes
1

answer
435

Views

Fetch blog entries with bootstrap custom theme and mezzanine

I'm new to mezzanine, I managed to install my custom bootstrap theme just copying templates and static files in the relatives folders in my django app. Assume in my index.html I have some blog entries like these Other Entries Blog Post 1 Contrary to popular belief, Lorem Ipsum is not simply random t...
user2697881
1

votes
1

answer
1k

Views

API call from one Django site to another

I'm pretty new to Python/Django but I have set up an REST API for one website (siteA.com), and would like another website (siteB.com) to be able to call this API and show some results. For this I have added the Django REST Framework and Django Auth2 Provider to siteA. I can now call the API using...
Michael Nieuwenhuizen
1

votes
1

answer
2k

Views

django with mysql what does 'maximum number of connections'?

I am writting simple application which django that can be used internally inside my office. probably 1000 people i say. I dont have any session handling, user handling. It is just a store/view process in the django. What i understood? 1) django closes reopens the database connection on each request...
Whoami
1

votes
1

answer
777

Views

get or create - unsupported operand type(s) for +=: 'builtin_function_or_method'

models: class TestVersion(models.Model): test = models.ForeignKey(Test) count = models.IntegerField(default=0) views: test = Test.objects.get(id=id) result = TestVersion.objects.get_or_create(test=test) result.count += 1 result.save() I have this error: unsupported operand type(s) for +=: 'builtin_...
orion95
1

votes
4

answer
3.5k

Views

How to use Django REST framework with a model with default value for foreign key?

Django==1.5.5 djangorestframework==2.3.8 I have a model with a Foreignkey: class Role(models.Model): name = models.CharField("Name", unique=True) def __unicode__(self): return unicode(_(self.name)) class Worker(models.Model): name = models.CharField("Name") role = models.ForeignKey(Role, default=1)...
Toff'
1

votes
1

answer
1.8k

Views

using morris chart in django

I am trying to use a morris chart in django. morris chart requires a data in format $(Morris.Bar({ element: 'mchart', data: [ { y: '2006', a: 120 }, { y: '2007', a: 75 }, { y: '2008', a: 50 }, { y: '2009', a: 75 }, { y: '2010', a: 50 }, { y: '2011', a: 95 }, { y: '2012', a: 100 } ], xkey: 'y', ykeys...
Laxmi Kadariya
0

votes
3

answer
28

Views

How can I identify a user without login feature in Django?

I'm making Django app where visitors can answer to questions without login feature. The number of each answer will be counted as 'votes', but I need to restrict a user to answer a question only once. I need someone's help who has experienced in this.
web coder
2

votes
1

answer
58

Views

allowing django-oauth-toolkit to issue jwt instead of random strings

I understand that django-oauth-toolkit is using oauthlib and oauthlib provides an example on the implementation of using jwt instead of random strings. However, I don't understand how I can get django-oauth-toolkit to issue jwt instead of random strings. Can anyone give an example implementation or...
Valerio Zhang
0

votes
1

answer
7

Views

Django admin panel renders “s” after table/model names

I have no idea what's going on, here's a screenshot
Jojo
0

votes
1

answer
24

Views

Disable read only fields in the response after posting the data

My model: class NewsID(models.Model): pass class News(models.Model): newsId=models.ForeignKey(NewsID,related_name = 'News', on_delete=models.CASCADE) lang_code=models.CharField(max_length=2) headline=models.CharField(max_length=100) class DefaultLanguage(models.Model): news_id = models.ForeignKey(N...
mounika kommineni
0

votes
0

answer
3

Views

django-oauth-toolkit-0.11 permission raises 401

Tech Stack:- Django1.10 + python3.6 + docker + DRF + React + Axios + Cross domain Error:- "detail": "Authentication credentials were not provided." As soon as I get my access_token I make a GET call with the same access token and every time I am getting 401 status code with the error mentioned above...
user734353
1

votes
2

answer
1.2k

Views

Using Django registration with a Flat UI template

I have created a template design for signup page using Flat UI. Now i want to use Django registration to register a user. I have goggled various resources but they are very complex and using Django inbuilt form to create a form. I need simple steps that i can follow signup.html(home/django/mysite/te...
Rohit.nib
1

votes
1

answer
2.2k

Views

Django QuerySet not serializable

I have the following function I'm using to make Ajax calls: 30 import json 31 32 def get_info(request): 33 run = Run.objects.values('nvp_build', 'lports', 'lswitch_stt') 34 measurements = Measurements.objects.values('maxfield') 35 apistats = APIStats.objects.values('num') 36 clusterdata...
cybertextron
1

votes
2

answer
990

Views

Dynamically add a placeholder to a form field

I have a Django form with a few typical fields: first_name = forms.CharField(label=_("First Name")) last_name = forms.CharField(label=_("Last Name")) phone = USPhoneNumberField(label=_("Phone Number")) email = forms.EmailField() password1 = forms.CharField(label=_("Password"), widget=forms.Password...
user1427661
1

votes
1

answer
326

Views

Django + rest-framework: serialize arbitrary query

I have three classes representing different sections in my models: SectionA, SectionB, SectionC. Each of these sections have associated a set of items (class Item in my model). I would like to get a json similar to this: { "sectionA": [ { "id": 1, "picture": "car_pic1", "category": "cat1" }, { "...
Esparver
1

votes
2

answer
767

Views

Django model inheritance creating or get from parent

Am trying to build a project and it seems that using model inheritance for my requirements can work the best, I have one base model in which I have several model uses it for inheritance. In the base model, I have a slug field which is unique across all (for integrity) In my child model, sometimes I...
Mo J. Mughrabi
0

votes
0

answer
20

Views

Which field is concerned by : 'a bytes-like object is required, not …'

I have on two django models the error a bytes-like object is required, not 'NoneType'. But I have no clue which field is concerned. Is there a general tip to identify the problematic field ? Django is great but error messages tends to be too broad. Here is the specific problem class Device(models.Mo...
Nicolas Zozol
0

votes
1

answer
21

Views

What do I use the Serializer create method for?

I am trying to implement a simple flow where the a user POSTs a secret code to an api endpoint. By doing so the user creates a foreign key relationship with another model. I achieved the desired behaviour on the serializer by overwriting the create method like so: class RegisterUserToCustomerSeriali...
Xen_mar
-1

votes
1

answer
31

Views

python calling one function from another

Im creating a serializer using python django DRF .Im creating a separate helper class and trying to override the create method. My helper class: class WorkFlowHelper: def create_levels(self,levels): for level in levels: workflow_level = WorkflowLevel() workflow_level.workflow=self, workflow_level.le...
Mohit Harshan
1

votes
2

answer
524

Views

Django - manually build HttpResponse, but want to use a template too

When returning an HttpResponse object with render_to_response you can provide a template and it will use that template and fill in all the {{ variables }} you've set within your template. If I want to build my HttpResponse object manually, is it possible to still use one of my templates in my templa...
Garfonzo
1

votes
1

answer
920

Views

Django/Tastypie - DELETE requests deleting everything

I have the following model class Open(models.Model): name=models.TextField() opened=models.DateTimeField(auto_now_add=True) user=models.ForeignKey(User) and the following resources class UserResource(ModelResource): class Meta: queryset = User.objects.all() resource_name = 'user' class OpenResource(...
user3264316
1

votes
2

answer
414

Views

Django Imagekit overwrite cachefile_name?

I'm trying to overwrite the cachefile_name property from the module django-imagekit. Here is my code: class Thumb150x150(ImageSpec): processors = [ResizeToFill(150, 150)] format = 'JPEG' options = {'quality': 90} @property def cachefile_name(self): # simplified for this example return "bla/blub/test...
nuss
1

votes
1

answer
110

Views

django models - query with manytomanyfield

I have problem with 1 query connected with ManyToManyField. We have 2 related models: User and Event. Model Event has 2 relations with User, it must have 1 organizer and any number or participants - organizer cannot be participant (I skipped the code which is responsible for validation of that). Now...
klis87
1

votes
1

answer
735

Views

Trouble installing factory_boy with pip

I'm working on a Django project. I'm setting up my environment on another machine and when I run pip install factory_boy, I get the following traceback: https://gist.github.com/JSweetman/35f59536d6b87a0ce8c0 Does anyone know what's happening? I installed factory_boy in a different environment on the...
Sweetman
1

votes
2

answer
523

Views

Python Code is not working on Browser

i am new to python and anyhow i managed to install Python on my Linux shared hosting. When I am trying to execute Python code in Shell terminal its working fine but i am not able to execute this code in browser directly and it just shows python code as text. In Shell: python public_html/index.py (...
user3667167
1

votes
1

answer
214

Views

What steps are needed to implement memcached in a Django application?

I have my existing Django web application that uses a MySQLDB without memcaching. I would like to implement memcaching to improve the responsiveness of this site. I see the instructions here. However, these instructions leave me with some unanswered question(s). Is this all I need to do to get memc...
Saqib Ali
1

votes
1

answer
340

Views

Is there any reason why a project has no settings.py file?

I have inherited a Django 1.4 project from an uncooperative developer and am having to find my way around and try and set up a dev environment. One of the issues I am having is a result of the fact there is no settings.py file in the project. In the directory where I would expect to find it, there a...
charliefortune
1

votes
1

answer
4.7k

Views

Is it possible to install a django package without pip?

I am trying to install django-dash to run one of the dashboard examples and see what it's like. I am on Windows running Python 2.7 and Django 1.6.5. I know the usual approach is to download pip then install the package using pip. However, I am on a work computer with no administrative rights so I c...
user1067577
1

votes
2

answer
454

Views

Django custom User model vs. profile model

I have a Django 1.5 app that currently has 2 different models for every user: the built-in User model, and my own MyUser model which contains information that is also used in the authentication process. I would like to merge these two models into one, or at least reference one from the other. If I w...
Tzach
0

votes
0

answer
3

Views

Django admin terrible performance get_form queryset filter when adding order_by

I'm encountering some terrible performance issues when trying to filter a forms queryset. I'm trying to filter a Model where a relationship already exists. The code is successful. But my queryset is not ordered. The moment I change to form.base_fields['sharepoint_mandate'].queryset = Sharepoint_Man...
Rach Odwyer
1

votes
2

answer
1.2k

Views

Custom URL for Wagtail model

I have a model like this: from wagtail.wagtailcore.models import Page class Blog(Page): created = models.DateTimeField(auto_now_add=True) ... .. Right Now, my default, if my slug is hi-there, the blog post is accessible on site_url:/hi-there/ but I want it accessible via site:url/2014/02/05/hi-there...
pynovice
1

votes
3

answer
1.4k

Views

Django ForeignKey: is it possible to ask for a name instead of an id?

My question is about django models and foreign keys. I searched for a similar question but it seems I didn't find it. My models are as follows: class Matches(models.Model): day = models.ForeignKey('Day') team_home = models.ForeignKey('Team', related_name="home_set") team_away = models.ForeignKey('Te...
foebu
1

votes
1

answer
844

Views

How to get Django ImageField name

How to get ImageField name In django. settings.py: MEDIA_ROOT = os.path.join(BASE_DIR,'myApp\media') MEDIA_URL = '/media/' DEFAULT_LOGO = MEDIA_ROOT + '\logo.jpg' I have following model: class Firm(models.Model): """ Firm model class """ ..... logo = models.ImageField(upload_to=MEDIA_ROOT, default=D...
vaibhav jain
1

votes
3

answer
815

Views

How can I find out why an object can't be JSON serialized? [duplicate]

This question already has an answer here: is not JSON serializable 2 answers I have a very simple use case of data that I wish to serialize to JSON, but I keep getting tripped by error TypeError: is not JSON serializable Here is the object I want to serialize - class MemberInfo: def __init__(self,...
self.
1

votes
2

answer
658

Views

how to check if django query success

when I use django query . I will use .exists to check if it is success. like: que = Image.objects.filter(id=1) if que.exists(): #do something I want to ask if I use update like this: Image.objects.filter(id=ac[0].id).update(url=image['url'],path=image['path']) how can I check the query...
user2492364
1

votes
3

answer
523

Views

Inserting a unicode text into pyx canvas

I have a set of UTF-8 characters that I would like to insert into a PyX generated pdf file. I have included # -*- coding: utf-8 -*- to top of the file. The code is somewhat similar to the following: # -*- coding: utf-8 -*- c = canvas.canvas() txt = "u'aあä'" c.text(2, 2, "ID: %s"%txt) c.writeEPSfi...
pariwesh

View additional questions