Tagged Questions
1
vote
1answer
25 views
Is it possible to add a datetime column to a manytomany field?
I was wondering if there was a way to add a datetime auto_now_add=True column to a manytomany field.
I have the following model.
class Photographer(models.Model):
user = ...
1
vote
1answer
18 views
Trigger An Action Based on value change of DateTimeField in Django
I would like to fire an event immediately at/after a certain DateTimeField in a certain model equals the value of datetime.now(). It is a field that marks expiration of a product, so as soon as it ...
1
vote
1answer
20 views
convert database object to string in django
models.py
class UserProfile(models.Model):
user = models.OneToOneField(User)
security_question = models.CharField('Question', max_length=255, null=True, blank=True)
security_answer = ...
0
votes
0answers
24 views
from django.db import models is broken in a django standalone crontab script
Before posting this, i'ved tried a wide variety of possibilities for getting this custom script to work (with no success). I have a script in a /lib directory which is being run in the crontab every X ...
0
votes
0answers
18 views
Load dropdown onchange of anyother value inside modelform class
Can we load values of a dropdown dynamically onchange of an event.
Let me explain through an example:
I am using a model form to dislplay a certain form, below is my form class
class ...
2
votes
1answer
41 views
Django admin encoding error
I am trying to add new user with admin interface and get this error:
IntegrityError at /admin/main/customuser/add/
������������: INSERT ������ UPDATE �� ��������������
"django_admin_log" ...
1
vote
1answer
23 views
issue in search and display the report
views.py
def search(request):
"""""""
if 'search' in request.POST:
search_keyword = request.POST.get('search_keyword')
reports = ...
0
votes
1answer
28 views
Django save or update model
I am using Django 1.5.1 and I want to save or update model.
I read the django document and I met the get_or_create method which provides saving or updating. There is a usage like;
...
0
votes
2answers
33 views
how to set username in user model to a random string
views.py
def index(request):
registerform = UserRegisterForm()
if request.method == 'POST':
if 'password' in request.POST:
registerform = UserRegisterForm(request.POST) ...
0
votes
3answers
47 views
Django .is_superuser field permission
By default from project directory by running manage.py createsuperuser command I am able to create a superuser, but the .is_superuser flag is the default django flag to differ superuser or other user.
...
0
votes
2answers
30 views
Django Model Class Missing in Admin
For some reason, the classes archive and album show all of their fields in the django admin panel, but image isn't showing an album field when I go to add an image to the image panel. If I open a ...
0
votes
0answers
28 views
Django FieldError and AttributeError exceptions after adding new field to model
I'm writing a multipurpose web application, and the data model is somewhat in flux.
I have a class Client defined as
class Client(models.Model):
client = models.IntegerField(primary_key=True, ...
1
vote
2answers
35 views
Django model export on MySql server
I imported the external database into my project , thereby converting it to models.py file using python manage.py inspectdb > models.py command.
Now I have edited the models.py file by adding ...
-2
votes
1answer
25 views
How to add django model fields after definition
I have a simple django model:
class Country(models.Model):
name=models.CharField(max_length=500)
iso_alpha3=models.CharField(max_length=3)
I need to add a new field 'default_city' after the ...
2
votes
1answer
44 views
Django Manual Debugging Process Flow
I am in the processing of developing a Django application. I had spent around 40-50 hours researching Django, and I am well on my way to making an application!
However, I am starting to come across ...
0
votes
1answer
24 views
Django INNER JOIN with GROUP BY queryset
How can I get the following SQL queryset in Django?
SELECT abbreviation, COUNT(tat_value) FROM t_tat
INNER JOIN t_tests ON t_tat.test_id = t_tests.test
GROUP BY test
These are my class models:
...
0
votes
3answers
29 views
How to add a calculated field to a Django model
I have a simple Employee model that includes firstname, lastname and middlename fields.
On the admin side and likely elsewhere, I would like to display that as:
lastname, firstname middlename
To ...
1
vote
3answers
26 views
django - 1. select 2. filter 3. then cut
I am trying to do this logic:
1. take all objects
2. filter them: all objs which has rate value >= 4
3. then take randomly 4 out of them.
how can i take randomly 4 out of them? not just ...
-1
votes
0answers
25 views
How to put User label restriction in Django 1.3
I am developing a site in Django 1.3 where I have 2 kind of users i.e Superuser and Client.
I am using Django's own user model, and I have also created a UserProfile model where I am storing user's ...
0
votes
1answer
23 views
Pagination works improper and creates error
I am making a Django Project, a Business Directory. Here I used the Pagination in the HTML page. But I am getting an error which says:
KeyError at /crawlerapp/search/"
I am following the ...
-2
votes
4answers
40 views
Alternative for Absolute Path in Django
I am making a Django Project, A Business Directory.
Here I have used ABSOULATE PATHS for Template rendering,
I thnk this might create problem in future.
Please look into my codes and Suggest me how to ...
1
vote
1answer
34 views
Recursive Relationship with a Description in Django Models
My project involves sorting many images. As part of this sorting, I want to be able to manually (as the user) mark several images as duplicates of each other with a brief description of why each ...
-1
votes
1answer
15 views
Foreign Key not Responding while fetching, Django
I am making a Django Project, A Business Directory.
In which while fetching data from DB, I am unable to fetch the data related to Foreign Key,
Please help
my models.py is::
from django.db import ...
0
votes
0answers
25 views
Sort objects by its one-to-many fields in django
I'd like get the newest thread of a given user. Currently, I query
t_array = Thread.objects.filter(participants=user)
Message.objects.filter(thread__in=t_array)[0].thread
Is there a better way to ...
-1
votes
1answer
24 views
Directory Model not working
I need to make a project which says::
Crawl and Display
Take this page - http://directory.thesun.co.uk/find/uk/computer-repair
Write a crawler using Scrapy, that will extract all the businesses ...
0
votes
2answers
50 views
Relate image model with similar images
In a django application, I will have a database of images all classified under the image class in my models.py. Unfortunately there is a possibility that some of these images are duplicates of each ...
0
votes
1answer
13 views
Extract Image Metadata in Django
I am trying to extract EXIF and XML data from many different types of images- JPG, PNG, etc. I am defining a class named image in my models.py file as follows:
class image(models.Model):
image = ...
0
votes
1answer
48 views
Saving custom user model with django-allauth
I have django custom user model MyUser with one extra field:
# models.py
from django.contrib.auth.models import AbstractUser
class MyUser(AbstractUser):
age = ...
0
votes
0answers
36 views
How can I get all models filtering by tag name in Django?
Basically I want to get a list of Post models, filtering them by the Tag objects contained in Post.tags
Here's my dumbed-down code:
def post_list(request, **kwargs):
posts = ...
0
votes
1answer
32 views
How to query multiple Django models describing denormalized tables
I'm trying to extract information from a number of denormalized tables, using Django models. The tables are pre-existing, part of a legacy MySQL database.
Schema description
Let's say that each ...
0
votes
0answers
23 views
Fixing Memory Leak in Django + Scikit-learn
How do you diagnose and fix memory leaks involving Django and Scikit-learn?
I'm working on a Django management command that trains several text classifiers implemented using scikit-learn. I'm using ...
0
votes
1answer
27 views
Prepairing list from a django query
I have a table where 5 columns are present, lets say col_a, col_b, col_c, col_d, col_e.
In that table I have 20 records. I want to write a django query which will return me 2 separate lists which will ...
0
votes
1answer
27 views
what about saving extra variable in a QuerySet?
for example i have a queryset say folder=Folder.objects.all().
what about saving some extra variable in it say
for i in folder:
i.fcount = 33
so that i can use it in templates easily like:
...
2
votes
3answers
31 views
Django execute task on time specified in model datetime field
got a simple question, I believe, but it got me stuck anyways.
Say I have a simple model:
class myModel(models.Model):
expires = models.DateTimeField(...)
and I want, say on the specified time ...
0
votes
2answers
30 views
Making portable Nodes in Django and using them to make Trees
What I am trying to make is something that can be done quite simply using pointers in C++. The idea is this, I have an object, and it is called a Node. This node will have a couple of characteristics:
...
0
votes
2answers
38 views
evaluate list to Object attributes in python / django
I just started with python and django and looking for a possibility to iterate through an objects attribute, to realize a search function over all fields.
The diff object classes an inheriting from ...
0
votes
1answer
43 views
Django users can only login if Boolean is set to true
I currently have a Poster model which is a ForeignKey to the Django user model.
class Poster(models.Model):
user = models.OneToOneField(User, primary_key = True)
bio = ...
1
vote
0answers
26 views
Django: Cannot resolve keyword on generic relationship
I want to filter my generic relationship by user i.e.
Entry.objects.filter(content_object__user=request.user)
But I get this message:
Cannot resolve keyword 'content_object' into field. Choices ...
1
vote
2answers
43 views
How to create Password Field in Model django
i want to create password as password field in views. Please can someone help me? Thanks in advance
**models.py**
class User(models.Model):
username = models.CharField(max_length=100)
...
1
vote
2answers
33 views
Django annotate() performance - is it supposed to be super slow?
Is it normal for annotate() to make things slow to a crawl?
Using annotate like this:
post_list = j.post_set.all().annotate(num_comments=Count('comment')).order_by('-pub_date')
Made it take four ...
1
vote
2answers
47 views
Why does Django's User Model set the email field as non-unique? [duplicate]
I am using Django's default User model and the email is not unique, now I have multiple users with the same email address.
You can have User_A with email address [email protected], and then a new ...
1
vote
2answers
37 views
Where to put helper functions when not using models and an ORM?
I have to use PyMongo in a Django project, althought I have always used either Django's ORM or Mongoengine. With the old setup, every model had its own method which did some actual work. This time, ...
1
vote
2answers
134 views
menu tab highlighting issue in Django
views.py
def edit_report(request, report_id):
"""Edit report navigation from action needed screen
"""
user = request.user
if 'report_id' in request.session:
del ...
0
votes
0answers
18 views
Django formfield_overrides for ForeignKey
I want to set custom widget for a certain model in admin panel.
I have a following structure:
class ChildForeignKey(ForeignKey):
pass
class Question(Model):
category = ...
1
vote
0answers
46 views
Store files in database as base64 encoded string
I use following model to store files in database in django app:
class Data(BaseModel):
_data = models.TextField(
db_column='data',
blank=True)
def set_data(self, ...
0
votes
0answers
42 views
Why is this Django model method not added to the model class?
I have a simple model named Ingredient which multiple profiles (instances of the class IngredientProfile) can be linked to.
class Ingredient(models.Model):
name = ...
0
votes
1answer
25 views
Django Admin: when displaying an object, display a URL that contains one of the fields
Here is an abstract base class for many of my "Treatment" models (TreatmentA, TreatmentB, etc):
class TreatmentBase(models.Model):
URL_PREFIX = '' # child classes define this string
code = ...
-1
votes
0answers
48 views
How to debug English datetime formats on an otherwise fully French website?
I have a fully working French website. All the apps I use are in French (for instance, django-cms). I do not need anything in English (viz. it is a monolingual site).
The Problem
Datetime formats ...
-1
votes
1answer
24 views
Django Image file upload default to random images
My use-case wants that if a user does not upload an Image I choose an image randomly from a pool of images created by the administrator.
That pool of images contain the ones uploaded by admin using ...
0
votes
1answer
21 views
how do i alter an uploaded file in django before its saved to “uploaded_to”?
i have a form like this:
from django import forms
from manupulators import Replacer
class ContentForm(forms.Form):
csvfile = forms.FileField( label='Select content file')
txtfile = ...