Tagged Questions
1
vote
1answer
18 views
Two different submit buttons in same form in Django
I have an UpdateView in Django.
I have just a normal submit button. When the object is updated correctly it redirects to an object list via success_url.
Can I make two different submit buttons: One ...
0
votes
0answers
18 views
Django ForeignKey db_constraint
I have a question about ForeignKey.db_constraint
If I understand the documentation correctly, if I set this to false a Foreign Key constraint is not created in my database correct? Which allows me to ...
0
votes
1answer
13 views
Django import models.py FK error
I've a model in notifications app.
class Notification(models.Model):
name = models.CharField(max_length = 255, primary_key = True)
description = models.CharField(max_length = 255)
And ...
0
votes
0answers
29 views
How to edit editable=False fields in django admin?
I have some fields that do not need to be displayed to the user, but need to be editable by the administrator in the admin panel. The solution provided by Manoj Govindan here only displays the field ...
0
votes
0answers
14 views
Insert to foreign key-linked table in django admin interface
I'm writing a rudimentary exercise app in django, with the following table structure:
Routine Exercise Segment
===== ===== =====
routine_name exercise_name ...
0
votes
1answer
16 views
Filter Django model on ForeignKeys that agree with each other
I'm trying to get records from a Model whose associated foreign keys (related_name=answers) collectively only have a single answer (answer = models.CharField()) among all that are related (in ...
0
votes
0answers
5 views
Django-threadedcomments customization
For custom data models in django comments, we are required to set the COMMENTS_APP in settings.py. But for the case of django threaded comments, the setting is already used for the app itself. So, how ...
-1
votes
1answer
30 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
40 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
2answers
28 views
Django Model OneToOneField without creating additional _id database column
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
28 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
24 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
32 views
Create nested dictionary dynamically 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
23 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
31 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
13 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
26 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
30 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
13 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
12 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
25 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
33 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
31 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
26 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
22 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
30 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
26 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
23 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
25 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
1answer
24 views
How do I use form data generate a custom Q() statement?
I have a search field named q in a form.When I am searching a member, I want it filter like below
results = Member.objects.filter(Q(mid=q) | Q(mobile=q)).order_by('pub_date')
In other forms I want ...
0
votes
2answers
16 views
Django rendering field not working
My model:
class preguntas(models.Model):
pregunta = models.CharField(max_length=200)
My views:
opciones = preguntas.objects.all()
return render_to_response(template, {"pregunta": pregunta, ...