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 ...
70
votes
9answers
33k 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 ...
35
votes
4answers
10k 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 ...
25
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 ...
33
votes
6answers
23k 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...
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: ...
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
8answers
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?
17
votes
3answers
2k views

Multiple Database Config in Django 1.2

This is hopefully an easy question. I'm having some trouble understanding the documentation for the new multiple database feature in Django 1.2. Primarily, I cant seem to find an example of how you ...
14
votes
1answer
8k views

How to introspect django model fields?

I am trying to obtain class information on a field inside a model, when I only know name of the field and name of the model (both plain strings). How is it possible? I can load the model dynamically: ...

1 2 3 4 5 15
15 30 50 per page