41
votes
3answers
9k views
Django dynamic model fields
I'm working on a multi-tenanted application in which some users can define their own data fields (via the admin) to collect additional data in forms and report on the data. The latter bit makes ...
74
votes
9answers
35k views
Programmatically saving image to Django ImageField
Ok, I've tried about near everything and I cannot get this to work.
I have a Django model with an ImageField on it
I have code that downloads an image via HTTP (tested and works)
The image is saved ...
38
votes
4answers
11k views
In Django, how does one filter a QuerySet with dynamic field lookups?
Given a class:
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=20)
Is it possible, and if so how, to have a QuerySet that filters based on dynamic ...
26
votes
4answers
12k views
Django: add image in an ImageField from image url
please excuse me for my ugly english ;-)
Imagine this very simple model :
class Photo(models.Model):
image = models.ImageField('Label', upload_to='path/')
I would like to create a Photo from ...
34
votes
6answers
25k views
Django auto_now and auto_now_add
For Django 1.1.
I have this in my models.py:
class User(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
When updating a row ...
21
votes
4answers
8k views
Django signals vs. overriding save method
I'm having trouble wrapping my head around this. Right now I have some models that looks kind of like this:
def Review(models.Model)
...fields...
overall_score = ...
12
votes
1answer
4k views
Using a Django custom model method property in order_by()
I'm currently learning Django and some of my models have custom methods to get values formatted in a specific way. Is it possible to use the value of one of these custom methods that I've defined as a ...
9
votes
1answer
2k views
how to manually assign imagefield in Django
I have a model that has an ImageField. How can I manually assign an imagefile to it? I want it to treat it like any other uploaded file...
12
votes
3answers
8k views
Django Blob Model Field
How do you store a "blob" of binary data using Django's ORM, with a PostgreSQL backend? Yes, I know Django frowns upon that sort of thing, and yes, I know they prefer you use the ImageField or ...
10
votes
3answers
1k views
How to add bi-directional manytomanyfields in django admin?
In my models.py i have something like:
class LocationGroup(models.Model):
name = models.CharField(max_length=200)
class Report(models.Model):
name = models.CharField(max_length=200)
...
13
votes
3answers
9k views
Django: ModelMultipleChoiceField doesn't select initial choices
ModelMultipleChoiceField doesn't select initial choices and I can't make the following fix (link below) work in my example:
http://code.djangoproject.com/ticket/5247#comment:6
My models and form:
...
2
votes
1answer
415 views
Optimizing performance of Postgresql database writes in Django?
I've got a Django 1.1 app that needs to import data from some big json files on a daily basis. To give an idea, one of these files is over 100 Mb and has 90K entries that are imported to a Postgresql ...
23
votes
7answers
13k views
Customize/remove Django select box blank option
I'm using Django 1.0.2. I've written a ModelForm backed by a Model. This model has a ForeignKey where blank=False. When Django generates HTML for this form it creates a select box with one option ...
26
votes
3answers
2k views
models.py getting huge, what is the best way to break it up?
Directions from my supervisor:
"I want to avoid putting any logic in the models.py. From here on out, let's use that as only classes for accessing the database, and keep all logic in external classes ...
27
votes
9answers
10k views
How do you serialize a model instance in Django?
There is a lot of documentation on how to serialize a Model QuerySet but how do you just serialize to json the fields of a Model Instance?