django-models

Django: Are row level permissions for instance specific rules, or are they about views?

Sorry for the confusing title. I tried to make it less verbose, but... What I'm wondering is: Does Django's new row level permissions (a) fix the design problem that comes with multi-tenant applications (I don't mean multiple users, but rather multiple instances working with the same db/db schema), or is it (b) just a more complex versi...

Django - Update model data before access?

Any pointers on how I can update the data for a model on each access? If I have code that accesses a Person object like so: p = Person.objects.get(username='darkpixel') I would like to fire off my own process to check an external site and possibly update the Person model before returning it. I'm hesitant to override the get method. I...

What is the best means to achieve efficient many-to-many scanning with Django models?

I have a many to many relationship in Django similar as this: class Account ( models.Model ): name = models.CharField( max_length = 30 ) user = models.ForeignKey( User, null = True, blank = True ) class Publisher ( models.Model ): publisherID = models.BigIntegerField( ) name = models.CharField( max_length = 30 ) lastRequested...

Django - Store unescaped html in model

I am trying to store raw, unescaped HTML inside one of my Django models for display on my home page. However, when I store it in a TextField it gets escaped, and ends up just being displayed as raw text. How can I store raw HTML in a Django model? ** EDIT ** It seems as if its not getting escaped in the model layer, but in the Template...

Limit number of model instances to be created - django

I have model from which I only want to create one instance, and no more instances should be allowed. Is this possible? I've got a feeling that I've seen this done somewhere, but unfortunately I'm unable to locate it. EDIT: I need this for a stupidly simple CMS. I have an abstract class for which FrontPage and Page classes inherits. I ...

django model and sqlite db creation bug.

I have the following model. from django.db import models class Client(models.Model): postcode = models.CharField(max_length=10) first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) address = models.TextField(blank=True) phone = models.IntegerField(blank=True) email = model...

Are Django's QuerySets lazy enough to cope with large data sets?

I think I've read somewhere that Django's ORM lazily loads objects. Let's say I want to update a large set of objects (say 500,000) in a batch-update operation. Would it be possible to simply iterate over a very large QuerySet, loading, updating and saving objects as I go? Similarly if I wanted to allow a paginated view of all of these ...

Ranking within Django ORM or SQL?

Hi, so... I have a huge list ranked by various values (eg. scores) So I grab the list ordered by these values: players = Player.objects.order_by('-score', '-karma') I would like to: Grab a player and get the neighbouring players P1 score:123 P2 score:122 YOU! score:110 P3 score:90 P2 score:89 Grab the...

Django: Does model_instance.clean() run before basic validators?

Let's say that I have a model: class Ticket(models.Model): client = models.ForeignKey(Client) color = models.CharField(max_length=255) def clean(self): self.color = self.client.favorite_color When I run this on the latest Django (head of the SVN from 15 minutes ago), if I hit save without selecting a client, I get...

What does this error mean: The model User has two manually-defined m2m relations ...

I'm running into this error when I attempt to syncdb: auth.user: The model User has two manually-defined m2m relations through the model FavoriteQuestion, which is not permitted. Please consider using an extra field on your intermediary model instead. I'm really don't understand what it means because I only see 1 model-to-model relation...

DB schema design in Django

I am in the process of creating a database to hold quality inspection records and learning Django at the same time. I may have jumped into creating models too soon as I've run into conceptual problems of how I'm defining the classes. The goal is to have a "master" inspection plan that defines what is to be inspected and an "instance" ins...

Django: Where does "DoesNotExist" come from?

All the time in Django I see DoesNotExist being raised like in db.models.fields.related.py. Not ObjectDoesNotExist which is defined in django.core.exceptions, but just DoesNotExist. Where is this exception class defined, or am I not fully understanding exceptions? I've checked that it's not in exceptions (at least not that I know of). I'...

Use of meta class in django

Can someone please explain why is meta class used in the following example. Ex: Class Employee (models.Model): name = models.ForeignKey(name) Gender = models.IntegerField() class Meta: ordering = ["Gender"] Thanks... ...

What's the difference between OneToOne and Subclassing a model in Django

For example: class Subdomain(Site): #fields here and class Subdomain(models.Model): site = models.OneToOne(Site) #fields here ...

Django reset not dropping tables

I just migrated my dev environment from Ubuntu Linux to Mac OSX snow leopard. All of this was working on Linux. On both, I have used MySQL for Django's db. Django's reset function is not issuing drop commands for all of my app's models. Here is my models.py (with the Forum and User object fields removed for brevity): from django.db imp...

How to create a django model field that has a default value if ever set to null

Given a model class Template(models.Model): colour = models.CharField(default="red", blank = True, null=True) How can I arrange it so that any access to colour either returns the value stored in the field, or if the field is blank/null then it returns red? The default=red will put "red" in the field when it's first created, but i...

Query for a ManytoMany Field with Through in Django

Hi All, I have a models in Django that are something like this: class Classification(models.Model): name = models.CharField(choices=class_choices) ... class Activity(models.Model): name = models.CharField(max_length=300) fee = models.ManyToManyField(Classification, through='Fee') ... class Fee(models.Model): activity = m...

Django: What is the stack order in Django?

I think that is the right way to ask it. I'm wondering which parts of the code execute first, second, etc. My assumption would be, but I don't know: Request Middleware View Model Middleware Response The reason I'm asking is because I want something to happen dynamicall in the Model based on a request variable and I'm trying to devic...

How to create form from two models in Django

I have UserProfile model defined in settings.py. Now I want to create registration form that have fields both from User and UserProfile models. Is there easy way to do it? I'm using uni_form to create nice looking forms if this helps. ...

Django: Model inheriting from base model with custom manager. Can the manager have dynamic variables?

I need to have all my models inherit this manager (Haven't tested this manager and it may be ridiculous so I'm completely open to suggestion/criticism on it as well): class AccountFilterManager(models.Manager): def __init__(self, account=None, *args, **kwargs): super(AccountFilterManager, self).__init__(*args, **kwargs) ...