queryset

Autorefresh div/table in Django if new queryset records available

Hello, I'm using Django and I would like to check if there are new records in queryset (which I display in table) and if there are new I would like to either update my table accordingly with fade effect or display most recent 5 records in another div/box. I've used jquery autorefresh, but it fades in / fades out even if there are no n...

django join querysets from multiple tables

if i have queries on multiple tables like: d = Relations.objects.filter(follow = request.user).filter(date_follow__lt = last_checked) r = Reply.objects.filter(reply_to = request.user).filter(date_reply__lt = last_checked) article = New.objects.filter(created_by = request.user) vote = Vote.objects.filter(voted = article).filter(date__lt ...

Get QuerySets from Many2ManyField (include related fields)

Hay, i have a model which houses a board class Board(models.Model): parent_board = models.ForeignKey('self', blank=True, null=True) Each board can belong to another board So say Linux Windows OS X can belong to a board called Computing These boards house a Thread object class Thread(models.Model): board = models.Forei...

Django: Update order attribute for objects in a queryset

I'm having a attribute on my model to allow the user to order the objects. I have to update the element's order depending on a list, that contains the object's ids in the new order; right now I'm iterating over the whole queryset and set one objects after the other. What would be the easiest/fastest way to do the same with the whole quer...

Annotate a queryset with the average date difference? (django)

I searched all over place for an answer to this but couldn't find anything. Perhaps this is just a stupid question or a really tricky one. Here it is: Let's say my model is this (pseudo django code): Event type = ForeignKey(EventType) name = CharField date_start = DateField date_end = DateField EventType name = CharField W...

custom quey in django

I'm building an ecommerce website. I have a Product model that holds info common to all product types: class Product(models.Model): name=models.CharField() description=models.CharField() categories = models.ManyToManyField(Category) Then I have SimpleProduct and BundleProduct that have FK to Product and hold info specific to the...

Custom unicode on already created object

I'm using permissions in my application. And in some case I need to create form only with permission field. I'm using ModelChoiceField and queryset with permission objects. permission = forms.ModelChoiceField(queryset = Permission.objects.all()) But permissions unicode is taking too much place in choice field. And it looks not so goo...

In Django, correctly making a queryset with multiple categories, multiple tags and search?

I have a list of data. This data model has many-to-many fields to both a categories model and a keywords model. The data model itself has a name and description. The data can have multiple categories and keywords. On the front end, the user can select a number of categories to filter down the data or do a search... So the data shown sho...

Get distinct values of Queryset by field

I've got this model: class Visit(models.Model): timestamp = models.DateTimeField(editable=False) ip_address = models.IPAddressField(editable=False) If a user visits multiple times in one day, how can I filter for unique rows based on the ip field? (I want the unique visits for today) today = datetime.datetime.today() yesterd...

Manager gives a queryset from files and not from a database

I would like to override the manager class in order to allow content data to be loaded from text files (here on of "/one directory/myPrefix_*") into content field instead of from a database table. class Things(model.Models): file = CharField(max_length = 25, primary key = True) content = TextField() objects = myManager("/...

Django QuerySet Custom Ordering by ID

Given a list of ids/pks, I'd like to generate a QuerySet of objects ordered by the index in the list. Normally I'd begin with: pk_list = [5, 9, 2, 14] queryset = MyModel.objects.filter(pk__in=pk_list) This of course returns the objects, but in the order of the models meta ordering property, and I wish to get the records in the order ...

Django: preventing QuerySet deletions on a model?

I have a model whose delete() method I have overridden. Because this is not called on a bulk QuerySet delete, I would like to disable QuerySet deletion or somehow assert against it happening. Is there any way to do that? ...

Breaking data into multiple display colums with Django

Overlap in terminology makes search for answers difficult for this one. I'm looking for advice on the best way to implement a multiple-column display of my QuerySet that fills each column top to bottom over X columns. Meaning that the number of items in each column equals the QuerySet count divided by X (number of columns). Using Offs...