Tagged Questions
0
votes
0answers
11 views
What is the easiest way to get custom serialized model with ForeignKey field
I am looking for an easy way to subclass rest_framework.serializers.ModelSerializer from Django REST framework so that it serializes to a special dictionary for foreign key models fields with the name ...
0
votes
0answers
21 views
Django: How to match a large number of URLField links to their corresponding comment CharField? (A Reddit-like app)
I’m attempting to create a system where users submit a URLField entry to a particular page along with a comment/description of what the URLField is (sort of like reddit) and then when visitors go to ...
0
votes
1answer
13 views
Add field for dynamically generated url in Django admin
I have a Django model that has a property called url that when accessed, returns a S3 signed url of a document on s3. Sign URLS have expirations, so I am not saving to the model, it needs to be ...
0
votes
0answers
15 views
Create an Activity Class Django
I am working on a project that needs to create an entry for every change done in the system and the changes done in the database, for example:
Jane update her profile profile address to 1st Street ...
0
votes
0answers
7 views
Annotate and count only selected objects within given date range in Django
I have a model similar to this:
class Page(models.Model):
title = ........
class PageViewed(models.Model):
page = models.ForeignKey(Project)
created = models.DateTimeField()
A new ...
2
votes
1answer
16 views
Correct syntax to inherit a models meta class?
What is the correct syntax to inherit a models meta class.
I have tried this:
Model:
class something(Base)
etc
class Meta(*args, **kwargs):
super(something).__init__(*args, **kwargs)
...
0
votes
0answers
25 views
How to grant access to staff users in Django admin interface?
I am quite surprised about not being able to find clear documentation about how to set up permissions for staff users in Django.
I have a typical Django website with a bunch of models. They are all ...
1
vote
1answer
28 views
How to order objects by foreign key existance in Django
I have following database structure
class Item(models.Model):
id = models.IntegerField(primary_key=True, unique=True)
pub_date = models.DateTimeField(auto_now_add=True)
class ...
0
votes
1answer
21 views
What are the performance differences using filter vs creating model functions
I was wondering if there is any difference in performance between using filters in django template and formatting the output with functions in models?
Say you have the following model:
class ...
-1
votes
0answers
28 views
Developing Blog app using Django Web Framwork
I am newbie to Django. Struggling with Django web framework. I have been trying to develop small blog app using Django Web framework.I am using MongoDb as backend
Followed tutorial at ...
0
votes
1answer
15 views
Get all models related to this model in django(via ForeignKey, ManyToMay)
I have to get all the models related to my current model. The relations can be by ForeignKey, ManyToManyField or OneToONeField, from this model or to this model.
For eg:
I have a model:
class ...
0
votes
1answer
16 views
Running total with annotated querysets in Django
I have a running total template tag which looks like
from django.template import Library
register = Library()
@register.filter
def running_total(list, var_name):
return sum(getattr(obj, ...
0
votes
1answer
20 views
Django ORM: wrapper for model objects
I am looking for some way to define some wrapper that is called before i call to Model.objects.all().
I want whenever i call, Model.objects it call my method (wrapper) and then return the objects ...
1
vote
2answers
41 views
Set default value of a field using classmethod in Django
I've found many similar posts on the web about this topic but no one state clearly which is the problem.
Code
class Item(models.Model):
@classmethod
def get_next_item_number(cls):
...
0
votes
2answers
23 views
Django - Redirect at login based on group
I am currently working on a Django project that has a number of user groups. After login, I am looking to redirect each user to a unique page created for that group.
I have already created the login ...
0
votes
0answers
14 views
django.db.utils.ProgrammingError: relation “blogango_blog” does not exist
I'm trying to create a blog using django-blogango given at "https://github.com/agiliq/django-blogango" using the following code
settings.py
INSTALLED_APPS = (
'django.contrib.admin',
...
-1
votes
1answer
23 views
Cannot Get Django to Search Database for a User Inputted Model Object Attribute
I'd really appreciate anyone helping me understand how to properly search model object attributes in django. First, I ask for an input string called userinput. I'm trying to get my views.py file to ...
0
votes
0answers
25 views
Non-existing onetoone field as zero on count?
2 of my django models are related by foreign key as shown below
class User(models.Model):
status = models.IntegerField(null=True, blank=True)
class Car(models.Model):
remarks = ...
1
vote
1answer
31 views
Django Tastypie Generic Relation
I have some models like that in a Django project:
class Link(BaseModel, BeginEndModel):
entity0_content_type = models.ForeignKey(ContentType, related_name='link_from')
entity0_object_id = ...
0
votes
1answer
17 views
Django Match IP in database
I am trying to check if the user's IP is in a model object I have. I added my IP in the database, but am not getting my code to respond accordingly:
views.py
def view(request):
try:
ip = ...
0
votes
1answer
19 views
django was_published_recently error TypeError: cannot compare naive and aware datetimes
I am learning Django on Jython and I have ran into an error while doing the Django Tutorial 01.
My System
Windows 7
jython2.7b2
Django-1.7c3
postgresql-9.3.5-1-windows-x64
...
0
votes
0answers
31 views
Scrapy django model import error
I've been trying to set up a scrapy spider using django and djangoitem. When I try running my spider, the item.py always fails to import the django app's model.
I set up a fresh django site and ...
1
vote
0answers
17 views
GeoDjango: 'QuerySet' object has no attribute 'transform'
I have these three models below in which I want to achieved the following:
Get all the geom(ButuanMaps) owned by the specific owner(Owner)
Display the geom(ButuanMaps) information from the ...
0
votes
1answer
21 views
Django Model __str__ function causing massive number of queries
I have the following models:
class PipeType(models.Model):
name = models.CharField(max_length=255, null=False, blank=False)
class Pipe(models.Model):
pipe_type = ...
0
votes
2answers
31 views
Django models, understanding one to one relationship
Im having difficulties understanding what is the purpose of a one to one relationship
I have a form where users fill out the information, and select a benefit type.
For example, I have a model of
...
2
votes
2answers
25 views
Adding user to group on creation in Django
I'm looking to add a User to a group only if a field of this User is specified as 'True' once the User is created. Every User that is created would have a 'UserProfile' associated with it. Would this ...
0
votes
1answer
17 views
Auto fill ForeignKey(User) with current signed in user in Django
I am working on a Django project where users will enter data into CharFields, but to organize the data, each users post is marked with their own username. However, at the moment, users have to go ...
2
votes
1answer
26 views
No such column error message
I read the tutorial from the django site and now I hit the wall. It seems very simple but it is giving me a problem. Everytime I run populate_rango.py script I get an error.
I have modified my script ...
0
votes
0answers
30 views
Django foreign key to different model.manager
I'm a noob to Python and Django so excuse my code I'm sure it's ugly.
I have a couple of models Group and Type, Type has a foreignkey to Group
Group contains records like (People, Location, ...
0
votes
1answer
15 views
Verify image height, width and filetype before uploading with ImageField in Django
I will soon enable a friend to upload images through the admin interface of my little Django project. I would like him to follow two rules :
Images must be 2000 x 1200 pixels
Images must be PNG ...
0
votes
2answers
26 views
Call a function after saving a model
I'm working on a Django application connected to a LDAP server. Here's the trick i'm trying to do.
I have a model called system containing some information about computers. When i add a new system, ...
1
vote
1answer
27 views
python-social-auth and Django, replace UserSocialAuth with custom model
I'm trying to integrate python-social-auth into an existent Django project.
I want to use an existent model for a user's social accounts, instead of UserSocialAuth (my DB already has data with it, as ...
0
votes
1answer
25 views
Append querysets in django form class
I have this class in django 1.4:
class ProgramForm(forms.ModelForm):
...other fields...
program_interests = forms.ModelMultipleChoiceField(
widget=forms.Select(),
queryset= ...
2
votes
0answers
24 views
Django data model policies
We have a Django-based website driven by a fairly involved data model, which has a growing number of Model types. Increasingly, the models have been gaining dependencies. While so far, we have been ...
0
votes
1answer
18 views
Field name with a leading underscore in Model
Given a following model:
from django.db import models
class A(models.Model):
_number = models.IntegerField()
Is it all right to have a leading underscore in a field name?
What about use in ...
1
vote
1answer
30 views
Inverse of ._meta to get Class of Reverse FK
If I have a class, to get the FK class, I can do:
MasterModel = Model._meta.get_field('master').rel.to
Given a MasterModel, how would I get the reverse FK? Something like:
Model = MasterModel.???
...
2
votes
0answers
29 views
Django recursive aggregates
Using django, lets say I have a model thats a Team model which has a foreign key to itself called grouped. I also have a model called Pen with a foreign key to a team.
class Team(Model):
grouped ...
0
votes
1answer
34 views
choose which account to create user
I created two type of user accounts using Abstractuser.
#models.py
class Profile(AbstractUser):
pass
class first(profile):
field = # Model field here
class second(profile):
field = # ...
0
votes
3answers
64 views
Django ForeignKey: is it possible to ask for a name instead of an id?
My question is about django models and foreign keys. I searched for a similar question but it seems I didn't find it.
My models are as follows:
class Matches(models.Model):
day = ...
1
vote
1answer
24 views
Efficiently grouping one model based on another's ForeignKey
I have two models, roughly:
class Event(model.Model):
pass
class Judgement(model.Model):
grade = models.CharField()
event = models.ForeignKey(Event)
Given N possible grades, I want to ...
0
votes
1answer
29 views
django two type of accounts
I want to create two type of user account in django 1.6
So that I am following one tutorial MULTIPLE USER TYPES IN DJANGO >=1.5
from django.db import models
from django.contrib.auth.models import ...
0
votes
1answer
25 views
How to filter based on either one of the columns
I have a table consisting of two columns: col1 and col2.
If myValue exist in either col1 or col2 it should be added to my queryset.
Using:
...
0
votes
1answer
24 views
Most efficient way to store a 5 point scale in Django
I have the following model for a song:
class Song(models.Model):
name = models.CharField(max_length=255)
artist = models.CharField(max_length=255)
rating = models.SmallIntegerField()
I ...
1
vote
1answer
16 views
Extended User model in django does not set fields when created even though arguments given
what happens is that when i create a new user using a registration form i created the user gets successfully created along with the extension which clearly has a field pointing to the User , however ...
0
votes
1answer
34 views
Django auth model Error: name 'User' is not defined
1. The error codes:
NameError: name 'User' is not defined
>>> myproject ME$ python manage.py shell
NameError: name 'User' is not defined
myproject ME$ python manage.py shell
Python 2.7.5 ...
-1
votes
1answer
67 views
Maximum recursion depth exceeded
This is my second question on this site. So please bare with me as I am new to programing in general.
so when I try to access my admin site for my django project. I get a message indicating "maximum ...
2
votes
1answer
35 views
No module named admin.sites.urls
I am new to Django, Python and this site. I have read the Django docs and the tutorial from " How to tango with django and now I hit a road block. I get an error No module names admin.sites.urls and ...
0
votes
1answer
25 views
Make Django models entries unique to each user
I am working on a system in Django where users will enter a stock symbol, that will be saved (using models). And when they login, they will see the stock symbols they entered. However, as it currently ...
0
votes
0answers
17 views
DJANGO— ./manage.py sqlclear south PERMISSION DENIED -NEED FIX
Question: 1. How do I fix the problem that the sqlclear does not work?
I did not know that South is a tool for Django that I can download with the command pip install South (supposed that I have pip ...
1
vote
1answer
58 views
Django filter query - doesn't work
I have problems with my Django, I want to write a very simple query but it doesn't work.
Model:
class Games(models.Model):
name = models.CharField(max_length=128)
path_to_folder = ...