Tagged Questions
0
votes
2answers
26 views
What's the difference between Model.id and Model.pk in django?
I saw the django documents use both sometimes? Are they identical? What's the difference and where is the reference? I only see document of pk.
BTW, does django reference cover all the methods of ...
0
votes
2answers
23 views
Django connect temporary pre_save signal
I've been struggling with a Django signal issue for a few days now and would appreciate your thoughts.
Scenario:
I wish to use a black box method (it's actually the LayerMapping loader in geodjango, ...
0
votes
2answers
43 views
How to get filter result in the order of query list in Django
I have documents something like this in my mongodb
{'id':1, 'url': www.aaa.com},{'id':3, 'url': www.ccc.com},{'id':2, 'url': www.bbb.com}
Model.Objects.filter(id__in=[1,2,3])
I want result for ...
0
votes
0answers
20 views
Django application for viewing web reports
I want to create a web application using django. I have a .csv file that is generated every week from the central database, and I need to use it to build a web reporting tool.
I'm wondering how to ...
0
votes
0answers
12 views
Best way to reverse a Transaction
I have a simple django website that has "Transaction's" Crediting one user's account and debiting another user's account.
Have used class based views to give each transaction a view, on that view and ...
0
votes
1answer
23 views
show parent in child screen django admin python
I'm new to python django and we decide to develop an application with this framework
for developing the admin we faced some issues here's a snippet of my code the models is like :
class ...
0
votes
1answer
17 views
Getting error in refering user object django
def itemconfirmation(request, pk):
item = Food_item.objects.get(id=pk)
userobj = request.user
user = UserProfile.objects.get(user=userobj)
if request.method == 'POST':
...
0
votes
0answers
14 views
Different behavior in Django when setting a Foreign key via obj.foo = bar vs. obj.foo_id = bar.id
We're experiencing a very strange bug where we have a unit test failing in our CI build (using CircleCI), but passing locally, and a very very weird change I've made that causes the test to pass in ...
1
vote
0answers
16 views
Django tastypie resources Import Error
I am getting this error while running my django application.
Internal Server Error: /
Traceback (most recent call last):
File ...
0
votes
1answer
48 views
What does Django return if no objects are found? And why do I get a DoesNotExist
I have a MySQL table in which I have Django register that a certain user is 'connected' to a unit. For this I have to check if the unit is allready connected to some other user. (model: ...
-1
votes
1answer
36 views
How to Implement django - pre_save and post_save?
I have tried much to implement django's pre_save and post_save, but still I am unable to generate the signal.
What I have is:
Class Client(models.Model):
.
.
. # some fields
Class ...
0
votes
1answer
22 views
How to save only date in Mongodb with Django DateField
I want to save only date in mongodb database.For that i used DateField in django models.But in database it is saving as,
ISODate("2014-02-24T00:00:00Z")
My code
models.py:
class ...
0
votes
1answer
25 views
Strategy For Interacting Instances Of The Same Model
Imagine you have a model like the one below. On each musician's page you want to show other musicians that have the same agent.
class Musician(models.Model):
first_name = ...
0
votes
0answers
28 views
Complete table get updated instead of single row in django
I have Table named TableColumn. and I am getting ColumnListObj with below django model api query.
Now I updated this object and save it.
ColumnListObj = ...
1
vote
2answers
32 views
django model instance edit
I have 3 models set as follows:
#models.py
class Room(models.Model):
room_number = models.CharField(max_length=20, primary_key=True, null=False, blank=False)
isolation_status = ...
0
votes
1answer
14 views
Django model delete: instance vs queryset delete
I need to know the best way to delete a model instance.
Instance delete example:
myModel = MyModel.objects.get(id=1)
myModel.delete()
Queryset delete example:
...
0
votes
0answers
14 views
Django many to many admin with custom through object
lets assume that I have such a model:
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=128)
class Group(models.Model):
name = ...
1
vote
0answers
12 views
Django use multiple databases dynamically without defining in settings
TL;DR: Besides my default django database, i need data pulled in from two different user-selected databases. not sure how to setup django to access these besides just running manual queries using ...
0
votes
1answer
11 views
Registered models doesn't show up in admin site
I'm writing a Django website, the directories and files in my project is like this :
Badil ->
Badil ->
__init__.py
settings.py
urls.py
wsgi.py
book ->
...
0
votes
0answers
14 views
Raise User Defined Exception in django Web app from models.py
This is my models.py file
class DiskDrive(models.Model):
deviceId = models.CharField(max_length=64, primary_key=True)
freeSpace = models.BigIntegerField()
def __str__(self):
...
1
vote
1answer
22 views
Django F() objects and custom saves weirdness
I've been working with Django F() objects to update my models, in order to avoid race conditions.
I also have a custom save method for my model (I want rebels to range from 0 to 100).
Here is some ...
0
votes
0answers
13 views
Using django-mptt with django auth_user
I am trying to create a user tree using django-mptt. I have auth_user table and a one-to-one mapping table UserProperties which has a foreign key of auth_user.
I added TreeForeignKey of django-mptt in ...
0
votes
2answers
15 views
How do I peroform django Model Validation to Exclude
In the 1.6 django tutorial, after speaking about testing, it illustrates a Poll should not be viewed with the index.html view when it has no Choice (a foreign key in this model). I've updated the ...
2
votes
2answers
20 views
Django: Should I convert an aware datetime instance to UTC before posting to a model?
I have aware datetime instances (where tzinfo = "America/Los_Angeles") that I would like to save to a model.
Should I convert it to UTC somehow before saving? Or can I just save it as is, since it's ...
0
votes
1answer
15 views
Get all objects not in M2M table in django
I have the following model:
class Invoice(models.Model):
invoice_number = models.CharField(max_length=100)
order_items = models.ManyToManyField(OrderItem)
How would I get all order_items ...
1
vote
1answer
30 views
Django model filter, reduce number of queries
I have a model called ListItem, which I break down into its types for the template as so:
list_items = ListItem.objects.filter(list__user=request.user.id)
type2list_items = ...
0
votes
1answer
12 views
Django calculated field and MVT usage
So, I have an interesting problem that I'm having a hard time approaching. I'm trying to intercept a queryset before sending a response to a template and add some instance/calculated variables. I ...
0
votes
1answer
21 views
How to multiply two fields in django
I have the following query:
result = self.order_items.values('rate', 'rate_description')
.annotate(quantity=Count('rate')).order_by('-quantity')
It gives me this:
[{'rate_description': u'CC ...
0
votes
0answers
24 views
Django: Calculate the Sum of the column values after filter
I have two models
User
name = models.CharField()
UserPoints
name = models.ForeignKey(User)
point= models.IntegerField()
...
What i need is ...
0
votes
0answers
23 views
Django: What is a good way to retrieve data spread across models?
I know this seems to be a too generic question, but I'm pretty new to Django, and after reading the full "Making queries" documentation section, I still don't understand how I'm supposed to make ...
0
votes
2answers
44 views
Dynamic database tables in django
I am working on a project which requires me to create a table of every user who registers on the website using the username of that user. The columns in the table are same for every user.
While ...
0
votes
0answers
8 views
Djcelery TaskMeta object causes dump with BaseDatatableView
I am using datatables along with BaseDatatableView and using as a model the TaskMeta model table that ships with djcelery. Here is my class:
class TaskListJson(LoginRequiredMixin, BaseDatatableView):
...
0
votes
1answer
34 views
Django: How to make a datetime object aware of the timezone in which it was created?
I am running a program that requests ocean tide data from a remote server. The time and date of this tide data is being computed based on my machine's local time zone. I want to use these local dates ...
1
vote
0answers
49 views
Why the same code outside the decorator works and not inside?
This code in models.py works:
f = auto_history()
f.history_connect_signals(Product, Product_History)
but this code doesn't work, in fact in that code doesn't do anything:
def ...
-1
votes
1answer
25 views
Find the Common first_name from Django Auth user Model
i need to find out the common first_name ( not case sensitive ) of the mail [email protected]
i'm using MongoDb and MongoEngine . how the query should be in normal ORM
User list:
first_name = ...
0
votes
2answers
13 views
How do I query a Django ForeignKey model field by choices' readable names?
Here is my class:
class UserProfile(TimeStampedModel):
# some fields
class UserCohort(TimeStampedModel):
CHOICE1, CHOICE2, CHOICE3 = range(3)
COHORT_TYPES = (
(CHOICE1, ...
0
votes
1answer
29 views
How can I call a classmethod from another class in python?
I'm programming an app for the edXproyect using Django and I need to retrieve some information from auth_user table and I don't know how to do it. I have this:
models.py
from django.db import models
...
0
votes
2answers
22 views
Calling a method from template
I seem to have a problem with calling a method from a django template. Given the model:
class Gallery(models.Model):
class Meta:
verbose_name_plural = "Galerie"
def ...
0
votes
1answer
18 views
python django make a subclass use the parents table
Hoi, this is my first post and I am pretty new to django.
[Edit: changed "from" to "mfrom"]
I have a generic class like
class Message(models.Model):
mfrom = models.TextField()
text = ...
0
votes
1answer
34 views
Django - Calling self save in a model method
I wonder if I change the model from inside a model method I shoudl call save() and if so how?
Example model:
class Case(Model):
some_number = DecimalField(max_digits=10, decimal_places=2, ...
1
vote
2answers
18 views
How can I override django model's delete method to save few fileds on delete
I have model Verification, I want to override django model's "delete()" method for this model.
And I have one more model VerificationHistory, which few common filed as in Verification.
On delete I ...
1
vote
4answers
100 views
Django: combine two ForeignKeys into one field
I need to implement the following:
The user shall be presented with a form that will have a drop down choice menu consisting of property names. There are two types of properties: general properties, ...
-1
votes
1answer
15 views
Django - accessing foreignkey's attribute
I am using the Django generic User model and I also added this additional model:
class UserImages(models.Model):
user = models.ForeignKey(User)
photo = ...
1
vote
0answers
33 views
Django 1.5 Admin - Object matching query does not exist - intermittent
Python 2.7.3
Django Version is 1.5
I am using the standard Django Admin DefaultModelAdmin for adding and changing objects.
Problem
When I add an object using Django Admin Add View - about one in ...
0
votes
0answers
22 views
Add default content to backend users in django
My web service holds files, which users can manipulate and then view.
I create new users automatically with an email address.
The difficulty I'm facing, is how can I set some default content to ...
0
votes
1answer
19 views
Filtering a DateField Object Django
I've read a whole bunch of similar Stackoverflows on this issue, however my issue seems to be more specific. I can't get the date to display in anyway but the default.
Here is the model in question:
...
0
votes
1answer
40 views
Retrieving most recent records from a table via fields automatically
Sorry for the unclear title, I really had no idea what to put in there which will describe my problem exactly, so you're welcome to edit my question.
I'm building my first Django webapp, which is ...
0
votes
1answer
39 views
Django - how can I make a cell in a table in the admin *changelist* interface editable only if it is null?
I would like my data to be editable inline in the Django admin page. However, I only want some fields columns in each row to be editable. These columns will change for each row. Basically, I want a ...
0
votes
2answers
36 views
Django User object error in models.py
I am writing my first Django project and using Django 1.7, and for my login and authentication I am using the Django User model. I am now creating my models. Project and User share a Many-to-Many ...
1
vote
1answer
25 views
Django - how do I filter ForeignKey choices in an editable column in a table on the admin page?
I have the following in my models.py:
class Size(models.Model):
size = models.CharField(max_length=20, primary_key=True)
class Book(models.Model):
title = models.CharField(max_length=100, ...