django-models

Better way to represent Many to many relationship in django admin

I have a unique problem the way it should be handled in django admin. I have following models structure... class Product(models.Model): name = models.CharField(max_length = 100) base_price = models.DecimalField(max_digits = 5, decimal_places = 2) def __unicode__(self): return self.name class Country(models.Mo...

Django admin App

Hi I am building a app. The app will build a Poll OR a Quiz. So my models will have a type field(Poll, Quiz) Now i would like to display the 2 "Types" in the admin App list. But i dont what to create two apps Poll and Quiz. Is there a way, to display the 2 options in the list and then when you click on lets say Poll, the type field is...

Tracking changes to Django Model instances

When you create or modify an object instance in Django's admin, a changelog entry is created. This is really nice for fairly obvious reasons. However my model's instances created by a normal user outside of the admin interface. No changelog is recorded to note its creation (not a huge issue) but I would like to track edits the user make...

django override User model

I'm trying to override the default User model in Django to add some logic into the save() method. I'm having a hard time trying to figure out out to go about this. I'm using Django 1.1 if that helps. I used post_save since i need to add the user into ldap.. I just added this into a models.py from django.db import models from django....

Convert SQL query to Django friendly format for application

I have an SQL query thats runs on the Postgres database of my Django based webapp. The query runs against the data stored by Django-Notifications (a reusable app) and returns a list of email addresses that have not opted out of a specific notice type. What I would really like to be able to do is to build an application that does this o...

How can I order elements in this case? - Django

So I have a list of models, don't think the structure of these models is important. In this case Articles. So these Articles are ordered by popularity between a rank of 1 to 100, all the other articles have no ranks. Whenever I update the rank of a model the model with equivalent rank must loose its rank. Any ideas? ...

Django - Two templates inheriting same parent, but nesting one another too?

I'm having some trouble with template inheritance. What I'm trying to achieve is a threaded comment system (using Django's comment framework). This requires comments who's DOM structure virtually identical to be nested. Here's the general layout of the issue: B and C inherit A C is nested inside of B (with include) Template D includes ...

Create or copy table dynamically, using Django db API

Hi, how can I perform smth like CREATE TABLE table_b AS SELECT * FROM table_a using Django db API? ...

How to add an Admin class to a model after syncdb?

I added some models in my models.py and I want to add an admin class to use a wysiwyg-editor in text-fields. Well, I know that Django itself doesn't support migrations and I've used South, but it doesn't work either. South doesn't "see" the change. Could...

save with many-to-many relationship in django problem

I have the following problem in django.. I have in models.py class Proposal(models.Model): #whatever.... credit =models.FloatField(null=True, blank=True) def save(): #here credit is saved based on some calculation (succesfully) class Author(models.Model): #whatever.... balance = models.FloatField(null=True,...

Why is post_save being raised twice during the save of a Django model?

I am attaching a method to the post_save signal of my Django model. This way I can clear some cached items whenever the model is modified. The problem I am having is that the signal is being triggered twice when the model is saved. It doesn't necessarily hurt anything (the code will just gracefully error out) but it can't be right. A ...

how to search related items into ManyToManyField?

Actually have this model: class MusicFile(models.Model): file = models.FileField(upload_to="files") def exist_in_playlist(self, playlist_id): exist = False try: mp = PlayList.objects.get(id=playlist_id, items__id=self.id) exist = True except PlayList.DoesNotExist: pass...

Django models, signals and email sending delay

Hello I have added a signal to my model, which sends email to some email addresses once a model is saved (via models.signals.post_save.connect signal and send_mail for email sending). This idea still makes delay for the users, when they save the model at the site, they have to wait until all those emails are sent and thats when they re...

How to sort order in Django Related Models (Generic relations)

My models: HitCounter: hits = models.PositiveIntegerField(default=0) object_pk = models.TextField('object ID') content_type = models.ForeignKey(ContentType, verbose_name="content cype", related_name="content_type_set_for_%(class)s",) content_object = generic.GenericForeignKey('conte...

Django -- How to filter objects with an "author" from a set of "authors"(users)?

How to filter objects with an "author" from a set of "authors"(Users)? The "objects" are Posts, having an author(ForeignKey to User). I'm pretty much stumped by this, so I'd appreciate help with it. Of course one could go about this the naive way, by manually filtering them, but that would hit the database real hard. Thanks anyway. E...

Can a generic.GenericForeignKey() field be Null?

I am creating an object which tracks changes (Updates) regarding the creation, updating and deletion of other so called UUIDSyncable objects in the database. This involves any object which extends the UUIDSyncable classes's save() and delete() methods being overriden, in such a way that it creates a new Update object recording the actio...

Explanation of contribute_to_class

I'm attempted to extend code, and have come across an issue, I don't understand a line of code. I know the outcome of it - but I don't understand how it happens and am naturally enough scared to change it. The line of code I've come across is this: MyGenericRelation().contribute_to_class(model, 'field_name') The result of this code i...

problem with select and related model

I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa = models.CharField(max_length=30) class IdfPraca(models.Model): numer_idf = models.ForeignKey(IdfPracownicy) [...] opinia = models.ForeignKey(IdfPracaOpinie) uwagi = model...

Django: Sort order the list in objects

I have list1 in order by id. Like this: ['4','2','1','17'] #edited How to get list2 from object Entry in order of list1. In the case Query ValueList, as well as on the question. [u'4', u'2', u'1', u'17'] Because some properties are not in QuerySet Thanks for your answers ! ...

How to get a list of queryset and make custom filter in Django

I have some codes like this: cats = Category.objects.filter(is_featured=True) for cat in cats: entries = Entry.objects.filter(score>=10, category=cat).order_by("-pub_date")[:10] But, the results just show the last item of cats and also have problems with where ">=" in filter. Help me solve these problems. Thanks so much! ...