django-models

Django unique_together and flagging objects as "deleted"

I'm implementing the first option discussed in "Marking for deletion in Django", that is, when an object is no longer active, I set a boolean to mark it as inactive. The specific reason I'm using this method is that although the object is no longer in active use, it may still be referenced and displayed in various records and reporting ...

How can i get a list of objects from a postgresql view table to display.

this is a model of the view table. class QryDescChar(models.Model): iid_id = models.IntegerField() cid_id = models.IntegerField() cs = models.CharField(max_length=10) cid = models.IntegerField() charname = models.CharField(max_length=50) class Meta: db_table = u'qry_desc_char' this is the SQL i use to create the table CRE...

How to create queues of objects in Django?

I am new to Django and I am trying to build a blog myself. I'm trying to create a feature I've seen implemented in Drupal using the nodequeue module. What I want to do is to be able to create queues of objects, for example, queues of blog posts. Below, I describe how I imagine the queues to work: the size of each queue should be user-...

Order queryset on calculated field

I have the following problem. I have these 3 models class Model1(models.Model): name = models.CharField() class Model2(models.Model): user = models.ForeignKey(User) parent = models.ForeignKey(Model1) class Model3(models.Model): user = models.ForeignKey(User) content_type = models.ForeignKey(ContentType, verbose...

How to filter queryset on calculated field provided by `extra` call in Django?

Hi all, Here is my django models: class Author (models.Model): name = models.CharField(max_length=255) removed = models.BooleanField(default=False) class Image (models.Model): author = models.ForeignKey(Author) name = models.CharField(max_length=255) height = models.PositiveIntegerField() width = models.Positi...

Trying to display a list with no primary key. (i dont even know if this is the right title)

I have a model with no primary key. it has the id's from other models. I want to call iid_ id. For example iid_id = 1. There are 21 rows with the number 1. I want to grab all the rows and display them on a HTML table. The Model: class QryDescChar(models.Model): iid_id = models.IntegerField() cid_id = models.IntegerField() ...

Django very tiny modification - logical delete

Hi, I want to make the following tiny modification to the Django framework. I want it to create a "deleted" field for each model I create, plus of course I want it to be checked as deleted when I delete it from the admin page instead of being physically deleted, and I dont want these records checked as deleted to be listed. I'm new to ...

Django limit_choices_to at circular relation

Hi, I've implemented a circular OneToMany relationship at a Django model and tried to use the limit_choices_to option at this very same class. I can syncdb without any error or warning but the limit is not being respected. Using shell I'm able to save and at admin I receive the error message: "Join on field 'type' not permitted. ...

'getattr(): attribute name must be string' error in admin panel for a model with an ImageField

I have the following model set up: class UserProfile(models.Model): "Additional attributes for users." url = models.URLField() location = models.CharField(max_length=100) user = models.ForeignKey(User, unique=True) avatar = models.ImageField(upload_to='/home/something/www/avatars', height_field=80, width_field=80) ...

Python .pyc files removal problem in django app

Hi i have a following solution structure in python: main_app main_app/template_processor/ main_app/template_processor/models main_app/template_processor/views everything works just fine on my local machine. as soon as code gets to server (it stopped working after i removed all .pyc files from svn), it doesn't see the assembly (if it...

Can Django admin handle a one-to-many relationship via related_name?

The Django admin happily supports many-to-one and many-to-many relationships through an HTML <SELECT> form field, allowing selection of one or many options respectively. There's even a nice Javascript filter_horizontal widget to help. I'm trying to do the same from the one-to-many side through related_name. I don't see how it's much dif...

Django: Ordering objects by their children's attributes

Consider the models: class Author(models.Model): name = models.CharField(max_length=200, unique=True) class Book(models.Model): pub_date = models.DateTimeField() author = models.ForeignKey(Author) Now suppose I want to order all the books by, say, their pub_date. I would use order_by('pub_date'). But what if I want a list of all a...

How can I get previous and next objects from a filtered, ordered queryset?

I have a page based on a model object, and I want to have links to the previous and next pages. I don't like my current solution because it requires evaluating the entire queryset (to get the ids list), and then two more get queries. Surely there is some way this can be done in one pass? def get_prev_and_next_page(current_page): ids...

How to pass initial parameter to django's ModelForm instance?

The particular case I have is like this: I have a Transaction model, with fields: from, to (both are ForeignKeys to auth.User model) and amount. In my form, I'd like to present the user 2 fields to fill in: amount and from (to will be automaticly set to current user in a view function). Default widget to present a ForeignKey is a selec...

django ModelManager inheritance

How do I inherit a ModelManager? class Content(models.Model): name = models.CharField(max_length=255, verbose_name='Name des Blogs') slug = models.SlugField(max_length=80, blank=True) objects = models.Manager() active = ContentActiveManager() class ContentActiveManager(models.Manager): def get_query_set(self): ...

Python/Django Model overriding the cleaned data

Hello I am currently working on a django project, in one of my Models I have a file upload and image upload, with the parameters of these two fields both are set to blank=True, however there is a stipulatation with this and it is that field can only be blank if one of the two is not, so for example, if the imagefield is complete then the...

How many data fields can I add to a Django model before performance really starts to become a factor?

If I want to create a Django model with 500 data fields, will that be slow? What is the upper limit on a Django model/table backed by MySQL on a powerful modern server? If I have 10,000 data fields will it be slow? At what point would I consider breaking down a really large table into smaller sub-tables? ...

Is there a better way to get ahold of a custom ImageField other than searching through foomodel._meta.fields()?

Calling foomodel.image on a model instance (where image is a custom ImageField) returns the instance of ImageFieldFile, not the ImageField itself. ...

Optional ImageField (Django)

Hi all, I'm having a problem with an ImageField in one of my models. It is set to blank=True, null=True (it is optional.) When I loop through a list of objects and use object.thumbnail.url, I get "Caught an exception while rendering: The 'thumbnail' attribute has no file associated with it." This only happens if no thumbnail has bee...

Diference between appengine_django BaseModel and db.Model

I'm using the Google App Engine helper for Django. This helper includes the following lines in its template: from appengine_django.models import BaseModel from google.appengine.ext import db # Create your models here. Should I derive my models from db.Model or from BaseModel? I've tried both and I don't see any difference. Both seem ...