24 views
Skip to first unread message

Abhishek Ghaskata

unread,
Sep 10, 2019, 4:09:38 PM9/10/19
to django...@googlegroups.com
I am getting error models has no 'objects' member.
So what should I do?

Duncan Jerry

unread,
Sep 10, 2019, 4:36:15 PM9/10/19
to django...@googlegroups.com
you should post images of the errors you are getting so that its easy for us to figure out a solution for you

On Tue, Sep 10, 2019 at 1:09 PM Abhishek Ghaskata <abhishekgh...@gmail.com> wrote:
I am getting error models has no 'objects' member.
So what should I do?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B5xdHPwjnyUVC_gw-QS9SW75RFj6obHvNJkKrwxtKSSmZQMzg%40mail.gmail.com.

Jani Tiainen

unread,
Sep 10, 2019, 5:07:40 PM9/10/19
to django...@googlegroups.com
Please paste your errors as plain text.

Images are really hard to read in mobile devices and searching image for keywords is really impossible.

Duncan Jerry

unread,
Sep 10, 2019, 5:16:30 PM9/10/19
to django...@googlegroups.com
exactly @Jani Tianien.. I strongly suggest that code snippet be snapped from whatever framework for easy understanding

laya Mahmoudi

unread,
Sep 15, 2019, 1:03:23 AM9/15/19
to django...@googlegroups.com

I have a search form including multiple fields for searching. I want to be able to search by entering value for any field and there should not be any force to enter values for all search fields:

my views.py:

image.png

template:
image.png


--
Laya Mahmoudi

Department of Information Technology Management

Allameh Tabataba'i University, Tehran, Iran

Shakil Ahmmed

unread,
Sep 18, 2019, 2:46:45 AM9/18/19
to django...@googlegroups.com

How to select all field but group by one field 
--

Anirudh Jain

unread,
Sep 18, 2019, 8:05:46 AM9/18/19
to django...@googlegroups.com
Example: YouModelName.objects.all().order_by('created_at')


This will sort all the objects in your model on the basis of date of creation on that object.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Shakil Ahmmed

unread,
Sep 18, 2019, 8:14:32 AM9/18/19
to django...@googlegroups.com
I want to select all field in a model but Grouy By One field.. Suppose i have country,people , and onther field in a model i want to  group by country but select all field

Anirudh Jain

unread,
Sep 18, 2019, 8:17:49 AM9/18/19
to django...@googlegroups.com
a = YouModelName.objects.all().values_list()
b= a.order_by('created_at')

Anirudh Jain

unread,
Sep 18, 2019, 8:18:58 AM9/18/19
to django...@googlegroups.com
Or you can use filter() instead of all()

Jani Tiainen

unread,
Sep 18, 2019, 10:14:14 AM9/18/19
to django...@googlegroups.com
Hi.

Technically that is impossible.

Group by is used to make sql aggregate to know aggregation criteria.

Let's take simple example:

Let's have table with columns name, job and salary.

Rows in table would be:

Jani,programmer,100
Ahmmed,programmer,100

Now lets calculate average salary of programmer:

select job, avg(salary) from table group by job

Now selecting name there doesn't make sense. If you would like actually represent names with average  salary you can do that by joining temporary table. So query would look like this:

select *,b.avg from table a join (select job, avg(salary) as "avg" from table) b join a.job = b.job

This should be possible with pure django as well.


--
Reply all
Reply to author
Forward
0 new messages