Tagged Questions
1
vote
1answer
11 views
Django get_model returns None for Mezzanine BlogPost model
I'm having a problem with get_model for Django. get_model works with every model I'm trying to get except for the BlogPost model from Mezzanine.
I've tried:
model = get_model('mezzanine.blog', ...
0
votes
1answer
18 views
Per user soft-delete model design in Django
I am designing an application where users send/receive records and I would like deletes to be separated for each user listed in the record (one user's delete will not hide the record from the other ...
1
vote
1answer
16 views
django unique relations not unique table
Take the following model:
class Foo(models.Model):
bar = models.ForeignKey(Bar)
name = models.CharField(max_length=30)
#...
so what this does is connect a Foo model to a Bar model and ...
0
votes
1answer
41 views
syncdb command not working properlly
I am trying to run the existing project.I had restored my database and installed all the required dependencies.While running syncdb,i got the below errors.
[root@localhost ]# python manage.py syncdb
...
0
votes
3answers
34 views
python _mysql_exceptions.ProgrammingError: (2014, “Commands out of sync; you can't run this command now”)
I am trying to run the existing project in centos machine.I installed packages from requirements.txt and it installed sucessfully.But while run "python manage.py runserver" i am getting the following ...
0
votes
0answers
15 views
Django: When to use custom user model vs profile model?
In the django docs, it says that defining user profile models with a one-to-one relation to the User model is still a useful design pattern to follow even though custom user models were introduced in ...
0
votes
1answer
31 views
Django: Upload Files and Save to Disk
I'm trying to upload some files through a form on my project and have the files save to disk. Currently, I am able to get the data to insert into the DB (postgreSQL), but the data is not being written ...
0
votes
1answer
33 views
Including saved user data in django email
I've created a script that allows me to send each user an email. I'm trying to include a list of terms that is saved to each specific user as text output in the email. I've managed to get the title of ...
1
vote
1answer
36 views
How to write Django model to get record from multiple tables?
class Game(models.Model):
total_players = models.IntegerField(max_length=10)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)
class ...
0
votes
1answer
37 views
Django manytomany field invalid literal for int() with base 10: ''
Okay so i have a model for "Modules" and this model covers all fields for 4 different types of modules i can create from it.
One of the modules requires a ManyToManyField so i can store recent ...
0
votes
1answer
21 views
State Pattern - Django models
I'm currently trying to implement the state pattern in Django. Take these models for example:
class Restaurant(models.Model):
name = models.CharField()
# other fields here ...
class ...
0
votes
1answer
39 views
Django South Error: AttributeError: 'DateTimeField' object has no attribute 'model'`
So I'm trying to migrate a table by adding two columns to it. A startDate and an endDate. Using south for Django, this should be a simple migrate. I have loads of other tables with dateTimes in them ...
-2
votes
1answer
44 views
Getting the object from just an object id
This seems simple, but I can't find how to do this.
From what I understand, auto-generated IDs in Django are globally unique - which is a feature I like:
If I have several models that inherit from a ...
0
votes
0answers
22 views
django model.object.values hitting db multiple times
I have a table called TranscationHistory.
class TranscationHistory(models.Model):
Transcation = models.ForeignKey(Transcation,db_index=True) ####
User = models.ForeignKey(User)
Debit = ...
0
votes
1answer
32 views
Get objects with similar foreign key
This is a basic question that probably has been asked before, but after searching quite a time, I couldn't find the answer. I'm not very familiar with the terminology in Django yet, so I've probably ...
0
votes
2answers
37 views
When merging querysets using 'or', you cannot have extra(select=…) on both sides
i think this is a simple and straight forward question, i have two query sets, i am merging them into one.
but this error occurred.
When merging querysets using 'or', you cannot have ...
3
votes
2answers
32 views
Django get all records of related models
I have 3 models for a to-do list app:
class Topic(models.model)
user = models.ForeignKey(UserProfile)
lists = models.ManyToManyField(List)
class List(models.model)
activities = ...
0
votes
1answer
27 views
Django: ModelForms: ImageField is always empty and rejected by ModelForm
I created a form based on several ModelForm elements. All fields work fine excluding the
ImageField. Due to the missing ImageField form.is_valid() always returns False - even though I pass ...
0
votes
0answers
28 views
Unable to get repr for error in filtering records by foreign key
I am currently having error on the following query.
projects.objects.all()
Here is my code:
Models.py
class ProjectManager(models.Manager):
"""A re-usable Manager to access a custom QuerySet"""
...
1
vote
3answers
47 views
Django direction of Many-to-Many relationship
I have two simple models Article and Topic, and as you can guess every article can belong to one or more topics.
The main functionality of this little app is to show all articles for a specific topic ...
0
votes
1answer
23 views
Django DecimalField generating “quantize result has too many digits for current context” error on save
I've got a model like:
class ModelWithDecimal(models.Model):
value = models.DecimalField(max_digits=2,decimal_places=2)
...yet when I try...
obj = ModelWithDecimal(value="1.5")
obj.save()
I ...
1
vote
2answers
30 views
Django, m2m with same model
I have following models in my django app:
Product model:
class Product(BaseModel):
company = models.ForeignKey(Company, null=True, blank=True)
title = ...
0
votes
1answer
60 views
python - inner join 3 classes [duplicate]
I have a problem, I don't know how to do an inner join (without raw sql) in python/django...
This is my classes:
class A(models.Model):
parameter1 = models.CharField()
class B(models.Model):
...
0
votes
1answer
40 views
Django Admin: Default values in StackedInline / TabularInline
I'm creating a website and it needs support for internationalization. The default languages are Portuguese, English and Spanish. I'm using the django-i18nmodel and so far it works great.
When the ...
0
votes
2answers
42 views
Django “Cannot resolve keyword” error. Can someone explain this?
I am just begining to learn how to use django. I am comming up with this error in my CLI
File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py", line 1337,
in setup_
"Choices ...
0
votes
1answer
43 views
django app: Cannot assign “''”: “ImageText.link” must be a “Link” instance
I'm building an app for my Django 1.5.1 and Django-cms installation.
The app meant to permit to upload an image linked to an URL.
My code :
cms_plugins.py
from cms.plugin_base import CMSPluginBase
...
0
votes
4answers
62 views
Django: How to get count of ValuesQuerySet?
I am trying to get count to work on a ValuesQuerySet. According to Django documentation
values = Model.objects.values()
will return a ValuesQuerySet which is a subclass of QuerySet
Returns a ...
0
votes
1answer
41 views
Django1.6, will transaction works for raw SQL?
Examples from offical document
from django.db import connection
def my_custom_sql(self):
cursor = connection.cursor()
cursor.execute("UPDATE bar SET foo = 1 WHERE baz = %s", [self.baz])
...
0
votes
1answer
19 views
Insert a new field in a specific admin view?
I'm trying to extend default Django's model with a new field.
In localsite/models.py I have the following code:
from django.db import models
from django.utils.translation import ugettext_lazy as _
...
3
votes
2answers
60 views
How to remove Add button in Django admin, for specific Model?
I have Django model "AmountOfBooks" that is used just as balance for Book model.
If this is not good pattern for database modeling just say so.
Anyway AmountOfBooks have two fields:
class ...
0
votes
1answer
28 views
Django request.session.save() authentication
Bit of a strange one and I have my reasons for doing this, I know Django does this out-of-the-box so put that to the side when I ask..... is it possible to create a authenticated session in Django ...
1
vote
1answer
27 views
How to force django to save immediately instead of doing a batch update after loop
I have this django views.py method that aims to insert many data into the db. It loops through arrays of models and, if an object isn't already on the db, it gets inserted.
This is what the code ...
0
votes
2answers
30 views
Django: Refactoring models into sub-modules
After the models.py in one app grew quite large, I've tried to move some of the classes into subpackages.
The old structure was something like this:
# File: assets/models.py
class Asset(...):
# ...
2
votes
1answer
30 views
How to get the class name of a ContentType in django
How do I get the class name in string of a ContentType? I tried it this way, but it didn't worked out:
class StreamItem(models.Model):
user = models.ForeignKey(User)
content_type = ...
0
votes
2answers
23 views
Django model search concatenated string
I am trying to use a Django model to for a record but then return a concatenated field of two different tables joined by a foreign key.
I can do it in SQL like this:
SELECT
...
0
votes
1answer
63 views
multiple tables join on basis of foreign key in single query set in django?
i am using sqlite3 database in my python django application: i am defining my table structure which is similar to my actual table schema.
table1 having three column:
1. id | primary key | int
...
0
votes
1answer
35 views
Django 1.5 Custom User for m2m field 'groups' clashes
Have I done this right? I have created a custom user in Django 1.5 which works. I now want to add a completely different type of user to the mix called WebUser allowing very simple access to front-end ...
0
votes
2answers
29 views
Can't update django datetime field to Null
My code is
Message.objects.filter(id=message_id).update(read_at='Null')
getting this error
ValidationError: [u'Enter a valid date/time in YYYY-MM-DD
HH:MM[:ss[.uuuuuu]] format.']
and the ...
0
votes
1answer
31 views
Django ORM non-strict search through multiple fields
There is the Model with some fields. I need to search some rows in the table and check multiple fields: f1,f2,f3.
So, query may be matched one to three fields. For example, f1 matches, but f2 and f2 ...
0
votes
1answer
51 views
Django - Insert Multiple Fields Into DB When Submitting Form
Sorry for kind of a newbie question, but I am looking to get this sorted and if it works with my current implementation with some minor tweaking, that would be ideal. What I want to do is have a form ...
0
votes
1answer
24 views
Python Django Multiple Database Committing Objects with Foreign Key Relations
I am using Django with multiple databases. I have a 'preview' database that takes messages uploaded by the user and these have to be previewed by an admin and 'accepted', at which point they are ...
0
votes
1answer
27 views
Django 1.5 Custom User Model not validating in templates
I have info in the django documentation to create my custom user profile, something pretty similar to what they show here, the problem is that when I am trying to access information about if the user ...
0
votes
1answer
31 views
django models - conditionally set blank=True
I am trying to build an app, where user can customize forms. The Following example contains classes for creating Fields (QuestionField, AnswerField) which is used by the admin and the BoolAnswer which ...
1
vote
1answer
26 views
The best way to insert new record with ID(PK) in other fields with Django ORM
I know django row queries - great.
But, is it possible make it in Django ORM?
For example for SQL:
INSERT INTO table (extra_ident) VALUES (id);
0
votes
1answer
35 views
Change Django Authentication Model password field
I am trying to modify my Django project authentication so I can use my own User model.
I have got it working so far, however I am unable to override the "password" field. I want to change the name to ...
0
votes
3answers
37 views
Django password = models.CharField(_('password'), max_length=128)
What relevance does the underscore have before ('password') in this line?
password = models.CharField(_('password'), max_length=128)
I looked at the Django documentation and it states that the first ...
0
votes
0answers
32 views
django translate model choices
I need translate a choices for a field on the model.
I have something like this:
from django.utils.translation import ugettext as _
from django.db import models
class MyModel(models.Model):
...
6
votes
2answers
15k views
Django request get parameters
I django request i have the following
POST:<QueryDict: {u'section': [u'39'], u'MAINS': [u'137']}>
how to get the values of section and mains
if request.method == 'GET':
qd = ...
5
votes
1answer
7k views
How to delete a record in django models
I want to delete a record. But I of a particular record. Such as
delete from table_name where id = 1;
How can I do this in a django model?
I am writing a function:
def delete(id):`
...
21
votes
4answers
18k views
Django DateField default options
I have a model which has a date time field:
date = models.DateField(_("Date"), default=datetime.now())
When I check the app in the built in django admin, the DateField also has the time appended to ...