0
votes
0answers
30 views

Django template: Looping through query_set and dictionary at the same time (or combining them)?

If I have a queryset called Fruit, whose model is something like: class Fruit(model.Models) name = models.CharField() producer = models.ForeignKey(Producer) In my view, I have a dynamically ...
0
votes
1answer
36 views

Django annotate fails when querying unique values

for a Django project I need to combine two parts lists into one. models.py: class UserBuild(models.Model): project = models.ForeignKey(Project) created = ...
0
votes
2answers
118 views

Django remove unicode in values_list

I did this operation: definitions.objects.values_list('title', flat=True) And it returns these results: [u'accelerate', u'acute', u'bear', u'big'...] You will realize that the results are all in ...
2
votes
2answers
105 views

Django Queryset: Need help in optimizing this set of queries

I'm trying to sieve out some common tag-combinations from a list of educational question records. For this example, I'm looking at only 2-tag example (tag-tag) which I should get an example of result ...
0
votes
0answers
57 views

django sorting using extra

views qs = Restaurant.objects.all() restaurants = qs.extra(select = {"avg_food_rate":"(SELECT food_rating_score FROM beenthere_restaurant WHERE food_rating_score != '0' )/(SELECT ...
1
vote
1answer
96 views

strange error in simple loop in django while getting data from db

I am getting data from django models and showing data in template using a for loop but it is saying: TypeError at /jobs/ __init__() takes exactly 1 argument (8 given) This is my view code that is to ...
2
votes
1answer
464 views

Django - queryset vs model in Generic View

I'm pretty new at Django and wondering what is the difference between defining model vs queryset in a generic view like ListView. Here's my code example in my urls.py file for the project: ...
0
votes
1answer
123 views

Check for multiple values in a M2M relationship in Django

In English, I want to check whether a user's type is either a viewer, a moderator, or an administrator. Here is the relevant part of my models.py class UserType( models.Model ) : name = ...
0
votes
2answers
208 views

“SELECT…AS…” with related model data in Django

I have an application where users select their own display columns. Each display column has a specified formula. To compute that formula, I need to join few related columns (one-to-one relationship) ...
0
votes
1answer
320 views

django queryset for a reservation system

I am building a django query to make apartment reservations. User enters start and end date and the db is checked too see if a clashing reservation already exists. That is to say, if any part of the ...
1
vote
2answers
126 views

django - how do I join the results of multiple models having foreign key the same user?

I have multiple models that point to the same user like this: class Model1(moldels.Model): user = models.ForeignKey(User) title = models.CharField() ... class Model2(moldels.Model): ...
1
vote
1answer
108 views

Django - Can a query update delete an existing record?

In my views.py I have something like this: a = Profile.objects.get(user=request.user.id) a.avatar = avatar.id a.save() From what I know when I do a save() if there is already a record with that ...
0
votes
2answers
71 views

django eliminate users out of queryset if they appear more than once

I have a recordset that captured a load of data, ie how many times someone has bought something. I am working on a small notification system based on their previous purchases that sends them an email ...
0
votes
1answer
402 views

Django Efficient Use of Queryset

I have the following view: from itertools import chain, groupby from django.db.models.aggregates import Sum from django.shortcuts import render_to_response, get_object_or_404 from ...
1
vote
1answer
52 views

Can i do an order_by on day in month?

I am trying to create a list of birth days, ordered by the dates, my query set is: birth_days = get_list_or_404(UserProfile.objects.order_by('-birthDate'), ...
0
votes
2answers
45 views

How to get the user email from auth.User when filterring a field in UserProfile?

I have a situation where i need to query the UserProfile model but need to get for every user record a field from the auth.User model: groups_list = ...
1
vote
1answer
141 views

Django: Query & render objects from a queryset into a list

I am making a query on one object which is a ForeignKey field on another object, and trying to render the second query as a list. Is there a proper way to access the second query as I'm getting the ...
0
votes
1answer
759 views

Deleting a record from database using Python

I have created a Django app and tested the application's performance by populating some 10,0000 records. Now i want to delete it using a python script. Can somebody help me in doing this. This is the ...
0
votes
3answers
519 views

Wildcard searching in Django

How can we do a wildcard searching in Django. If i am filtering username from a list in database, how is it possible to display the filtered data with those exact usernames or part of it.? def ...
0
votes
1answer
274 views

In Django using fiter() then get() on queryset?

Can I combine the use of filter() and get() on querysets to return an object in a django view? I have the following view; def my_view(request, city, store, item): item = ...
2
votes
2answers
266 views

Select a subset of foreign key elements in inlineformset_factory in Django

I have a model with two foreign keys: class Model1(models.Model): model_a = models.ForeignKey(ModelA) model_b = models.ForeignKey(ModelB) value = models.IntegerField() Then, I create an ...
1
vote
4answers
656 views

Django: Generating a queryset from a GET request

I have a Django form setup using GET method. Each value corresponds to attributes of a Django model. What would be the most elegant way to generate the query? Currently this is what I do in the view: ...
1
vote
1answer
1k views

chain filter and exclude on django model with field lookups that span relationships

I have the following models: class Order_type(models.Model): description = models.CharField() class Order(models.Model): type= models.ForeignKey(Order_type) order_date = ...
2
votes
2answers
181 views

django, a good way of querying a distinct model

Assume I have a such model: class Foo(models.Model): name = models.CharField("ad",max_length=25) type = models.ForeignKey(Type) So at the database I have Foo objects with same name field ...
2
votes
3answers
775 views

Django's list_details views saving queryset to memory (not updating)?

I have a custom model manager that looks like this: class MyManager(models.Manager) def get_query_set(self): '''Only get items that are 'approved' and have a `pub_date` that is in ...
1
vote
2answers
2k views

Specifying Django Related Model Sort Order

I have Django models that are lists of items and I want the items on each list to have a separate sort order. Maybe list 1 will sort line items by name, list 2 by date, and list 3 by priority. The ...
1
vote
1answer
286 views

How can I use Django admin list and filterering in my own views?

I’m just beginning to learn Django and I like the automatic listing in Django admin and the way you can configure filters and what columns to show. Is it possible to use it in my own applications? ...
4
votes
3answers
2k views

Select Distinct Years and Months for Django Archive Page

I want to make an archive_index page for my django site. However, the date-based generic views really aren't any help. I want the dictionary returned by the view to have all the years and months for ...