Tagged Questions
-1
votes
1answer
26 views
How do I return objects' attributes in Django?
I am working on a friendship system with Django and I am using the following model:
class Friendship(models.Model):
sender = models.ForeignKey(User, related_name='friendship_sender')
receiver = ...
0
votes
1answer
37 views
How to do complex query like this
I have the following get and get_queryset methods in my CustomersListView class:
def get(self, request, *args, **kwargs):
"""
:param request:
:param args:
:param kwargs:
:return:
...
0
votes
1answer
14 views
Django Model OneToOneField from existing primary key
I'm working with an Account model and I want to inner join it with a Settings model without having to create an additional settings_id column in my Account model, because the PK on the Account table ...
0
votes
0answers
26 views
Pass arguments to multiple forms with the same request in Django
I am new in django and I have a doubt:
Is possible pass arguments to a several forms.
Scenario:
I have an html table rendered with django-tables2, in the first column I have a drop down button. One ...
1
vote
2answers
17 views
Which timezone does Django use in DateField's auto_now_add?
How does Django write the date field when the field is marked with auto_now_add attribute?
Is it like datetime.now().date() or timezone.now().date()?
In other words, which timezone does it use to ...
0
votes
0answers
27 views
Create nested dictionary from table in python
I want to make a dynamic menu that has sub-menus from values stored in a database using TEMPLATE_CONTEXT_PROCESSORS
my model "menu" has this:
-short_name
-description
-url
...
2
votes
1answer
22 views
How can I limit the number of queries when retrieving all related objects from multiple models?
Lets say I have this model:
class MyLogModel(models.Model):
log_stuff = models.CharField(max_length)
class MoreLogModel(models.Model):
word = models.CharField(max_length)
my_log_model = ...
0
votes
2answers
26 views
How to make an object JSON serializable
I have an object called Exercise which has a lot of variables and i only wish to serialize two variables: id and name for each Exercise.
This is how my vars looks like:
{'exercises': [<Exercise: ...
0
votes
1answer
12 views
Django create bounded form with ManyToMany Field
I want to create bounded form with ManytoMany field
i have my models.py like this
from django.db import models
from django.contrib.auth.models import User, Group
class Message(models.Model):
...
0
votes
1answer
21 views
Django ORM: avoid multiple queries when saving models with foreign key relationships
Let's suppose I have 3 models: A, B, C, with C having foreign keys relationship with both A and B.
How can I avoid multiple queries, when saving a C model if I have the necessary info to retrieve A ...
0
votes
2answers
28 views
Unable to set default values in Django models
I am trying to set default values for few fields like Date, Integer and CharFields, but when I am setting it like default=12 (in case of integer) it is not being reflected in page. However a default ...
0
votes
1answer
12 views
Getting Distance in Miles with GeoDjango
I'm using TRUE lat and lon. I've enabled geography in the model as I'm dealing with large distances.
The below works on the entire list of cities but how do I get the distance between a single ...
0
votes
0answers
11 views
Django DateTimeField model field not assignable
I have a DateTimeField in my model. I assign a date to that datetime field with a particular timezone. I do something like this:
date = datetime.now(tz=pytz.timezone('US/Pacific'))
...
...
1
vote
1answer
23 views
Django admin. Hide field on change select field
I have model:
class CategoryField(models.Model):
selectfield = models.IntegerField(choices=SELECT_FIELD_CHOICES, default=1)
verified = models.BooleanField(default=True, ...
0
votes
0answers
16 views
Removing querryset from ManyToMany relationship in Django
I have models Amenity and Property shown below
class Amenity(models.Model):
feature= models.CharField(max_length=500,verbose_name='feature')
class Property(models.Model):
name = ...
0
votes
1answer
19 views
Knowing if a foreign key is selected or not selected
class Foo(models.Model):
name = models.CharField(max_length=256)
total = models.SmallIntegerField()
availability = models.SmallIntegerField()
class Bar(models.Model):
somthing = ...
...
1
vote
0answers
29 views
many to many relationship between different types using a through table
I've been trying to understand how to get a many to many relationship working correctly. Here's the simplified model of Entity and Event. The relationships I'm trying to model are:
Entities have a ...
-1
votes
0answers
23 views
Django 1.7 error with views render
my problem is when, I print returned error in home.
Reverse for 'category' with arguments '(1,)' and keyword arguments '{}' not found. 0 pattern (s) tried: []
Here I show the code with which I am ...
0
votes
0answers
22 views
How To Handle Child Classes When Avoiding Concrete Model Inheritance
Sorry: had a hard time coming up with a title for this one
I am writing an app that allows users to add web videos and categorize and tag them for easy searching and management. I need a Video model ...
0
votes
1answer
15 views
Rendering different image formats in Django template
In my Django project, I have a template where I have to upload an image corresponding to the the dynamic instance. For eg: Corresponding to a Student model, I have a template so that I can serve each ...
0
votes
1answer
30 views
Django 1.7: Passing around unsaved instances throws “unhashable” exception
I'm migrating over to Django 1.7 currently. I have some signals that pass an unsaved model instance, which now throws TypeError: Model instances without primary key value are unhashable.
I'm ...
0
votes
0answers
30 views
How to view /template data from existing db using model in Django
I managed to connect existing mySQL with Django , but when I tried to view in my app. using :
from task.models import stats
data = stats.objects.all()
for e in data:
print e.name, 'starts on', ...
1
vote
1answer
23 views
Update Table Relationship in Django Admin
I'm trying to create a directory of sites, I'm new in Django. What I need is: one site can have many payment processors and one payment processors (Paypal, Payza, etc) can belong to many sites. I'm ...
0
votes
1answer
20 views
Django Add ManyToMany Relationship to Admin User Form
I'm using the django admin feature as the backend administration for my site. It seems to work perfectly, out of the box for my needs, except for one thing. One of my models has a many-to-many ...
0
votes
0answers
25 views
Django: dynamic models
Few words about project:
Site to create ads. In admin page we can create new Category(model in db) and create N different types fields to this category. Then we can create Post in this Category.
I ...
0
votes
1answer
21 views
Django: Delete model object using template
I am currently using models to have users enter data, using templates (not admin) that is then stored, at which point the users can then see all the data they entered. I would like to also give users ...
0
votes
2answers
29 views
Django polls tutorial - would like to delete and start again
I'm working through the django 1.6 tutorial here:
https://docs.djangoproject.com/en/1.6/intro/tutorial01/
Various things have gone wrong along the line (the database now contains several ...
0
votes
0answers
25 views
Django model field getter for admin?
I have in model:
ip = models.IPAddressField(db_column='Ip', verbose_name=u'IP')
def save(self):
self.ip = int(struct.unpack('>L', socket.inet_aton(self.ip))[0])
super(Servers, ...
0
votes
1answer
22 views
Updating one-to-many reference field in Django also updates other objects
I have an existing DB with two tables, called Identities and Accounts, which I'm trying to manage using Django ORM.
Identities has a one-to-many relationship with Accounts, and I modeled the two ...
0
votes
1answer
20 views
django views.py - display positiveinteger text value
I have a models class with a select list / positive integer field.
class AchievementDetails(models.Model, FillableModelWithLanguageVersion):
ACADEMIC_ACHIEVEMENT = 1
COMMERCIAL_ACHIEVEMENT = ...
0
votes
2answers
44 views
How Do I Select From Two Different Tables in Django?
I have these Models and I want to be able to select from the first two.
class Comments(models.Model):
post_id = models.ForeignKey('Posts')
content = models.CharField(max_length=480)
...
0
votes
1answer
29 views
Django filter ManyToMany field
class Page(models.Model):
name = models.CharField(max_length=128)
categories = models.ManyToManyField(Category, null=True, blank=True)
class Category(models.Model):
# some fields
I want ...
0
votes
1answer
17 views
Querying all objects in order of creation except for the latest one
As the title explains, lets say I have the following queries:
main_article = Article.objects.latest()
prev_articles = Article.objects.all().order_by('-created')
I want the prev_articles to ...
0
votes
0answers
23 views
Splitting App Administration Panel In Django
I am currently using the Django admin panel on an app that has 10 different models. When I log in, I click on the app and I see 10 different urls which lead to dashboards in which I can ...
2
votes
1answer
21 views
using post_save signal to update foreignkey field
models.py
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
class website(models.Model):
uid = ...
0
votes
0answers
25 views
Serializing classmethods in Django 1.7
When I try to run manage.py makemigrations on Django 1.7, I get the following error:
ValueError: Cannot serialize: <bound method ModelBase.get_default of <class ...
1
vote
1answer
37 views
How to create django models with custom foreign sets
I have a 1:many relationship on two Model classes in my Django application:
class CheckList(models.Model):
user = models.ForeignKey(User, related_name='checklists')
name = ...
0
votes
1answer
16 views
Create model after group has been created django
I need to create an instance of my model every time a new group has been created in the admin panel.
I read some information about signals, but i can't figured it out at all.
Thank you very much
1
vote
1answer
22 views
Django objects and Multiprocessing
I'm attempting to pull a whole host of info as quickly as possible and have the following code to assist in it:
pool = Pool()
products = Post.objects.filter(affiliate_product_url=None)
res = ...
0
votes
1answer
24 views
How to manually define one to one key of legacy database in Django
I'm trying to define models for a legacy database.
Database schema:
CREATE TABLE sysuser
(
id serial NOT NULL,
login character varying(20) NOT NULL,
passwd character varying(80) NOT NULL,
...
0
votes
0answers
18 views
DjangoRatings vs. Simple IntegerField like button functionality: How to restrict likes by IP Address?
I am creating a small/basic app that allows visitors to navigate to different pages of content and make anonymous posts on each page and also comment on their own or other people's posts. I would like ...
0
votes
0answers
37 views
i got this AttributeError: 'module' object has no attribute 'QuerySet'
class EntryQuerySet(models.QuerySet):
def published(self):
return self.filter(publish=True)
class Entry(models.Model):
title = models.CharField(max_length=200)
body = ...
0
votes
2answers
191 views
AssertionError: False is not true when moving to Function Based Views
I am using Test Driven Development methods to create a basic blog in Django 1.6.
I followed this tutorial but wanted to change to using Function Based Views since I'm just starting with Django.
I ...
2
votes
2answers
2k views
ForeignKey vs OneToOne field django [duplicate]
I need to extend django user with some additional fields . I found 2 different ways there
class UserProfile(models.Model):
user = models.OneToOneField(User)
#other fields
OR
class ...
9
votes
4answers
2k views
Django - How to get admin url from model instance
First of all, thank you for reading my question.
I'm trying to send an email to a user when a new model instance is saved and I want the email to include a link to the admin page for that model ...
13
votes
3answers
6k views
Django script to access model objects without using manage.py shell
I'm writing a script to import some model objects into the database my django application uses. In the past I've solved this by running ./manage.py shell and then import myscript. I'm sure there's a ...
3
votes
3answers
4k views
Django Boolean Queryset Filter Not Working
This has been frustrating me for the better part of an hour.
I have the following model:
sold= models.BooleanField(default=False)
And the following view code:
properties = ...
11
votes
4answers
6k views
Show a ManyToManyField as Checkboxes in Django Admin
Is there a simple way to show a ManyToManyField as Checkboxes in Django Admin?? Any suggestions?
2
votes
2answers
4k views
Django self-referential relationship?
I'm trying to create model Page, page should be able to have "child pages" too.
My model code below keeps crashing Python on my Mac (python 2.6.1) and Ubuntu 10.04 (python 2.6.5):
from django.db ...
49
votes
1answer
6k views
Why doesn't django's model.save() call full clean?
I'm just curious if anyone knows if there's good reason why django's orm doesn't call 'full_clean' on a model unless it is being saved as part of a model form.
Note that full_clean() will not be ...