django-models

Map raw SQL to multiple related Django models

Due to performance reasons I can't use the ORM query methods of Django and I have to use raw SQL for some complex questions. I want to find a way to map the results of a SQL query to several models. I know I can use the following statement to map the query results to one model, but I can't figure how to use it to be able to map to relat...

add request to django model method?

I'm keeping track of a user status on a model. For the model 'Lesson' I have the status 'Finished', 'Learning', 'Viewed'. In a view for a list of models I want to add the user status. What is the best way to do this? One idea: Adding the request to a models method would do the trick. Is that possible? Edit: I meant in templatecode: {{ ...

Django Snippets Required

Hey guys, I'm a really tight schedule to code up a prototype for a website. I'm working with Django and am just starting out. Can you suggest open source Django snippets for the following: 1) A User Registration system (Registration/Authentication/Sessions) 2) A Rating System (Preferably a x/10 or 5 stars rating system) 3) A tags bas...

Django QuerySet order

Hi, I am new to both django and python but I am beginning to get a grasp on things. I think. I have this problem and I can not seem to find an answer to it. (Though I assume it is really simple and the limiting factors are my google skills and lack of python/django knowledge) The scenario: a user can opt in to recieve temporary job op...

django object get/set field

Can I get the value of an object field some other way than "obj.field". Does something like "obj.get('field')" exist? Same thing for setting the value of the field. ...

Standard Django way for letting users edit rich content

I have a Django website in which I want site administrators to be able to edit rich content. Suppose we're talking about an organizational info page, which might include some pictures, and some links, where the page is not as structured as a news page (which updates with news pieces every few days), but still needs the ability to be easi...

Different ManyToManyField widget

The default django 1.0.2 ManyToManyField widget (a multi-select) is difficult to use when there are a lot of things in the select box. Is there another widget available that gives a comma separated list of id's in a textarea? If this is not available what do I need to do to write one, and have it show up on ModelForm.as_p() and in the...

Appengine - How to change an entity of kind Model to Polymodel without losing existing entities

I am using appengine and appenginepatch for django I have a class defined in my models that was inheriting from db.Model. I've now changed it to polymodel.PolyModel. Since making the change, my existing entities are no longer retrievable. Is there a way to access them or convert them? Whats the recommended procedure for changing an ent...

Moving objects from one many-to-many association to another in django?

Hey all, Got a question. Say I have two models in a many-to-many relationship (Article, Publication). Article A is in Publication One, Two, and Three. I want to remove it from those publications and put it into Publication X. The django documentation covers deleting objects and adding objects, but I don't want to delete nor add objects,...

In Django, how can I pre-populate an edit form from a model/child, but save submission as new instance?

I'm trying to prepopulate a ModelForm and an inlineformset_factory with an instance of a Model, BUT when the user submits the form, I need to create a new instance of the Model and it's related child records. Example Model: class Artist(models.Model): artist = models.CharField(max_length=100) class Song(models.Model): artist =...

How to store data in Django Model without having an input field

I have model for example like this: class Meeting(models.Model): date = models.DateTimeField(default=datetime.datetime.now) team = models.CharField(max_length=100) class Meta: verbose_name_plural = u'Meetings' ordering = ['-date', 'team'] def __unicode__(self): return u'%s %s' % (self.date, self...

Does order of declaration matter in models.py (Django / Python)?

I have something like this in models.py class ZipCode(models.Model): zip = models.CharField(max_length=20) cities = City.objects.filter(zip=self).distinct() class City(models.Model): name = models.CharField(max_length=50) slug = models.CharField(max_length=50) state = models.ForeignKey(State) zip = models.ManyToManyField(ZipCode) Whe...

Is it possible to define names of model's fields dynamically?

Now I have this code: class Mymodel(models.Model): xxxx_count = ForeignCountField(filter={'foreign_table__xxxx': True}) yyyy_count = ForeignCountField(filter={'foreign_table__yyyy': True}) zzzz_count = ForeignCountField(filter={'foreign_table__zzzz': True}) qqqq_count = ForeignCountField(filter={'foreign_table__qqqq': Tr...

Why is mysql ignoring the 'obvious' key to use in this simple join query?

Hello. I have what I'd thought would be a simple query, but it takes 'forever'. I'm not great with SQL optimizations, so I thought I could ask you guys. Here's the query, with EXPLAIN: EXPLAIN SELECT * FROM `firms_firmphonenumber` INNER JOIN `firms_location` ON ( `firms_firmphonenumber`.`location_id` = `firms_location`....

Is Django model validation handled just through the forms API?

Is this the only way to create custom model validation? To do it using the forms? What if I want to send data to the database through means other than forms? ...

What is the best way to access stored procedures in Django's ORM.

I am designing a fairly complex database, and know that some of my queries will be far outside the scope of Django's ORM. Has anyone integrated SP's with Django's ORM successfully? If so, what RDBMS and how did you do it? ...

Annotate a sum of two fields multiplied.

I have three models, simplified for the example: class Customer(models.Model): email = models.CharField(max_length=128) class Order(models.Model): customer = models.ForeignKey(Customer) order_status = models.CharField(blank=True, max_length=256) class Lineitem(models.Model): order = models.ForeignKey(Order) quantit...

Django Manager Chaining

I was wondering if it was possible (and, if so, how) to chain together multiple managers to produce a query set that is affected by both of the individual managers. I'll explain the specific example that I'm working on: I have multiple abstract model classes that I use to provide small, specific functionality to other models. Two of t...

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... ...

How do you make a Django app pluggable?

Say for example I have a Blog app that I want to be able to drop into different projects, but I always want the Blog to be associated with some other model. For example, in one case I may want it to be associated with a user: site.com/someuser/blog But on another site I want it to be associated with, say, a school: site.com/someschool...